owner Permission changed automatically

HI all,

We had created new user using the command useradd -d /home/selva -s /usr/local/bin/bash selva . But it didnt created the home directory on /home. So i manually created, copied skel files manually and changed the owner from root to selva. At the same time i observed that so many files copied from /etc to /home directory on the same time and some files owners are showing as selva.

Output of /etc/default/useradd
#default useradd options
HOMEDIR /home
GROUPID 20
INACT -1
EXPIRE
CHOWN_HOMEDIR no
CREAT_HOMEDIR no
START_PROGRAM /sbin/sh
SKEL_DIR /etc/skel
ALLOW_DUP_UIDS no
COMMENT
Output of selva id:
uid=109(selva) gid=20(users)
Group output of Users:
users::20:root

Fully I am confused...I have attached files which was created automatically in /home and see the owners and my history file.

u missed -m argument

# useradd -d /home/selva -s /usr/local/bin/bash -m selva

--Shirish Shukla

For that only I did manually...but why should unwanted files copied from /etc/ to /home. and also owners of all users home directory changed to selva as owner. and some /usr/, /var/, /opt files also got changed...What will be the reason behind...?

We assume that you were logged in as "root" and typed one of more commands incorrectly which caused unexpected change to the system.

What did you actually type?
(If you have a .sh_history file , have a look at it with the "strings" command).

Ps. I can't read your ".jpg" attachments. Can you post in text?

HI Shirish Shukla,

By missing -m, how the files will copy and file permission got changed.

When u missed -m option then -d /homepath get updated in /etc/passwd file ... but dir /homepath will not get created that had happend at your case ... and you had created that dir after and copied that files from skel dir right ...

Better recreate the user ... with right parameters ...

--Shirish Shukla

Finally managed to read the .jpg examples.

The issue is with these commands. I've posted them as comments
because we don't want people executing them.

# bad line 1 # vi /etc/passwd
# bad line 2 # cp -rf /etc/skel/.* /home/selva/
# bad line 3 # chmod -R selva:users /home/selva/.*
# bad line 4 # chown -R selva:users /home/selva/.*

1) NEVER use "vi" on /etc/passwd. If you are expert, use the "vipw" command, but in your case you probably just needed "view".

2) This command is terrifying. Try this to see what I mean:
ls /etc/skel/.*
Compared with:
ls /etc/skel/.??*

3) This command is a syntax error and didn't do anything.

4) This command is terrifying. Try this to see what I mean:
ls /home/selva/.*
Compared with:
ls /home/selva/.??*

The problem is your use of " .* " when you expected it to match filenames starting with a " . " . It actually expanded the the parent directory " . " in both occasions. Your problem was made so much worse by using recursive (-r/-R) and overwrite (-f) options to commands when there was no point in that context.
It should be possible to use the "ls" commands I posted above to determine which files were copied or changed in error. However because you used the "-f" switch to "cp" be careful about detecting files which were overwritten (if any).
It's such a mess that it may be quicker to go back to backup, but it depends on how many files you had in /home and whether all permissions are easy to fix.

The change of permissions of some files in /usr /var /opt will be because many of the original files in /etc are LINKS and having copied the lot to /home/selva your commands then issue a recursive "chown" on the copies. Scary. I'm surprised that this system is still running, but don't reboot the system without repairing all the permissions of system files.

QED.