~$ su
Password:
#
Perhaps its needed to add a new user for new person that needs to work on the system, or you will need to add a user and a group for some software package to work securely. Creating user or updating user information is done with the 'useradd' command. So let say I need to create new account for my mother who just found out how cool is Linux. Her username will be 'mom' and I'm gonna add her on the system now:
# useradd mom
# cat /etc/passwd | grep mom
mom:x:1001:1001::/home/mom:/bin/
With this command I simply added new user called 'mom'. Secondly I wanted to check out did it accualy succeed with the second command. Yes, mom is added in the '/etc/passwd' file. But what about hose other data? Every entry in 'passwd' file means is formated as:
[account name]:[password]:[user ID / UID]:[group ID / GID]:[home directory]:[shell]
We see that her UID and GID are both 1001, these numbers are unique to user 'mom' and her initial group (which is also called 'mom'). Mom's home directory is '/home/mom. The last parameter is the type of shell she'll use, in this case 'sh'.
Letter 'x' means the password is encrypted. But what is actually her password? I didn't type any password when creating account. Her password was randomly generated cause I didn't specify it, and I actually don't know it. But thats no problem, cause I know root password, and I can change any password for any user anytime with 'passwd' command. I'll do it now for mom:
# passwd mom
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Now any user that knows her password can login to her account with 'su mom' command.
Now I'm noticing one other thing. I cannot go to moms home directory cause it doesn't exist, and I need to create one for her. I'll do it with this command:
# mkdir /home/mom
# chown mom /home/mom
# chgrp mom /home/mom
Now mom has her own directory in which she can put her stuff. Directory 'mom' also belongs to her 'mom' group. But I could have saved myself from the trouble if I just put '-m' option when creating her account like this:
# useradd -m mom
The 'm' option automatically creates user directory.
The process of creating a new user is over, I'll just change her default shell to 'bash' and change my file permissions so she can't digg through my files:
# usermod -s /bin/bash mom
# exit
exit
~$ cd ..
~$ chmod o= tvrtko
For further details of a particular command see the 'man' pages.
No comments:
Post a Comment