| Understanding Multi-user Systems | ||||||||||||||||
Linux is like an corporate office building
|
||||||||||||||||
| User Accounts: Regular Users vs. Root | ||||||||||||||||
|
||||||||||||||||
| Creating and Managing Users: useradd, usermod, userdel | ||||||||||||||||
|
Ubuntu has two commands for creating users
Creating a User (useradd)
low-level standard Linux commandpowerful but 'dumb' creates the user but might not create a home directory or set a password need to use sudo because adding a user changes the system command to add Bob as a user sudo useradd -m -s /bin/bash bob
Creating a User (adduser)
script (specific to Debian/Ubuntu) that wraps around useraddruns interactively creates the home folder automatically prompts to set a password immediately Modifying a User (usermod)
sudo usermod -c "Bob Smith, Accounting" bob
to lock an account sudo usermod -L bobto unlock an account sudo usermod -U bob Deleting a User (userdel)
to remove user access
sudo userdel bobremoves bob from system registry does not delete the account's home directory to delete the user and home directory sudo userdel -r bob |
||||||||||||||||
| Setting and Changing Passwords: passwd | ||||||||||||||||
|
when user bob was created he was not assigned a password an account without a password is locked unless configured otherwise to set a password use sudo passwd bobthe system will for the password to be entered twice > no password characters will appear on the screen Changing Your Own Password
any user can change their password without using sudo
passwdwill ask for current password then the new one Forcing a Password Change
to force bob to change his password
sudo passwd -e bob-e flag is for expire at bob's next login he will be prompted to make the change |
||||||||||||||||
| Understanding /etc/passwd and /etc/shadow | ||||||||||||||||
|
when useradd is run the information is stored in simple text files
The User Registry: /etc/passwd
file contains the list of all usersreadable by all users cat /etc/passwdthe first and last lines of the file are root:x:0:0:root:/root:/bin/bash ... bob:x:1001:1001:Bob Smith, Accounting:/home/bob:/bin/basheach line consists of seven colon-separated fields
The Secret Vault: /etc/shadow
file contains actual encrypted passwordsreadable only by root sudo cat /etc/shadowoutput lines will each contains seven colon-separated fields bob:$6$kH...long_string...:19265:0:99999:7:::
Manual Editing
can edit these files with nanoprobably shouldn't use commands like usermod instead |
||||||||||||||||
| Creating and Managing Groups: groupadd, groupmod, groupdel | ||||||||||||||||
|
Creating a Group (groupadd)
create new entry in the /etc/group file
sudo groupadd developers Modifying a Group (groupmod)
to rename a group
sudo groupmod -n engineering developers Deleting a Group (groupdel)
no longer a need for the group
sudo groupdel engineering |
||||||||||||||||
| Adding Users to Groups: usermod -aG | ||||||||||||||||
add bob to the developers group
sudo usermod -aG developers bobflags are critical
use -aG (Append to Groups) to add a new group without deleting the existing ones Verifying Group Membership
groups boboutput shows two groups bob belongs to bob is bob's primary group bob : bob developers |
||||||||||||||||
| Switching Users: su and sudo | ||||||||||||||||
|
The Substitute User (su)
to switch users
su bobenter bob's password to complete current directory doesn't change to get to bob's home cd ~to return to original user type exit if su is entered without a username, system assumes you want to be root will ask for password on Ubuntu the root account is disabled by default no password is set security feature su usually fails The SuperUser DO (sudo)
sudo lets user run a single command as rootevery admin has their own password Getting a Root Shell with sudo
use one of the commands below
sudo -i sudo suwill ask for password as root use extreme caution to return to original user type exit |
||||||||||||||||
| Configuring sudo Access: Understanding /etc/sudoers | ||||||||||||||||
|
bob can't use sudo not listed in /etc/sudoers The Sudo Group
any member of the sudo group can use the sudo commandfirst user (1000) is automatically added to make bob an adminstrator sudo usermod -aG sudo bobnever edit /etc/sudoers in vim or nano always use sudo visudoopens file in a safe editor when a save is attempted, it checks grammar if error found, save is refused can use visudo to create granular permissions |
||||||||||||||||
| Best Practices for User Account Security | ||||||||||||||||
|
Lock Unused Accounts
sudo usermod -L bob Enforce Strong Passwords
can install a module called libpam-pwquality to force users to pick complex passwords
Disable Root Login
force everyone to use sudosudo commands are logged in /var/log/auth.log Limit Sudo Access
standard permissions are safer
Clean Up Old Groups
when a project finishes delete the group
Use SSH
for remote access encourage users to use SSH Keys instead of passwordsthey are significantly harder to hack |
||||||||||||||||
| Summary | ||||||||||||||||
covered
key points
|