2. Adding user accounts
-
Let's create a new user:
useradd --helpuseradd -m -s /bin/bash test1Only the superuser can create new accounts, so let's use
sudo:sudo useradd -m -s /bin/bash test1The option
-mtells it to create a home directory for the user, which is by default located at/home/, and the option-stells it what shell to use for this user.ls /home/ls -al /home/test1/Users normally cannot access the content of each other. Superuser can access everything.
sudo ls -al /home/test1/We should also set a password for
test1:sudo passwd test1 -
Let's switch to this user and try some commands:
sudo su -l test1sumeans: 'switch user'pwdwhoamiidWhen a user account is created, the system assigns it a number called user ID or uid, which is mapped to a username for the sake of humans. Each user is also assigned a primary group ID (or gid) and may belong to additional groups.
exitBack to the first user.
pwd
whoami
id -
User accounts are defined in
/etc/passwdand groups in/etc/group. However the passwords of the users are stored in/etc/shadow:ls -l /etc/passwdfile /etc/passwdless /etc/passwdYou can see that besides the normal users there are also some system users, including the superuser (or root), with uid=0.
ls -l /etc/groupfile /etc/groupless /etc/groupls -l /etc/shadowfile /etc/shadowless /etc/shadowYou don't have permission to see the content of this file.
sudo less /etc/shadow -
The command
chowncan be used to change the owner and/or the group of a file. Let's try it:chown root: foo.txtwhoamiSuperuser privileges are required to use it. Let's try with
sudo.sudo chown root: foo.txtls -l foo.txtchown test1:root foo.txtls -l foo.txt