Skip to content

Latest commit

 

History

History
169 lines (122 loc) · 6.1 KB

File metadata and controls

169 lines (122 loc) · 6.1 KB

Lab1.2: Using Linux for user management

What am I about to learn?

Today's lab session is essential to have a solid start in this module. Make sure you complete all the tasks before the next class.

Lab 1 part 2 focuses on how to:

Lab 1.2 Learn how to use Linux commands to manage users of your VM.

Lab 1.2: User management in Unix (Ubuntu 18.04)

This tutorial describes the steps to manage users with different security privileges. We will mainly use the sudo keyword, representing the system's superuser. We already used the sudo in lab 1.2 to run commands (for example, installing software).

The sudo (from the “superuser do” phrase) represents a group of accounts with special security privileges related to installing/uninstalling software, manipulating folders and files, and making system and application configurations.

Note that numbering continues from Lab 1.2

  1. Let’s create a new user with a different username; for example, you can use your name. In my case, I will create a new user called bilbo from the Shire 🌲.
    • Note that we are still logged in as our existing user (with sudo privileges).
    • We will use the sudo adduser command followed by the user name, in our case, bilbo.
    • Enter a password and then complete the rest (or leave it empty by pressing Enter).
      • My password is myprecious
$ sudo adduser bilbo
...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
...
Changing the user information for username
Enter the new value, or press ENTER for the default
    Full Name []: Bilbo Baggins
    Room Number []: Bag end
    Work Phone []: 
    Home Phone []:
    Other []:
Is the information correct? [Y/n] Y
  1. Our new user bilbo 🙋 is now ready. * bilbo has a new directory in /home/bilbo. * But bilbo is not a superuser (sudoer).
  2. To add the new user as sudo, we need to use the usermod command.
$ sudo usermod -aG sudo bilbo
  1. This command adds bilbo to the sudo group. What does -a and -G stand for? Simple running the usermod command. This shows a list of possible options.
$ usermod
Usage: usermod [options] LOGIN
Options:
...
-G, --groups GROUPS		new list of supplementary GROUPS
-a, --append			append the user to the
                 			supplemental GROUPS mentioned by 
                  			the -G option without removing 
                            	him/her from other groups
...
  1. Let’s recap; we have a new user bilbo that is also a sudo user.

    🚩 The Linux community usually refers to sudo user as sudoer. Respectively, yoda and bilbo are both sudoer users.

  2. I will switch to the new user account using the following command.

$ su - bilbo

Note that the dash option helps you to change to the new user while at the same time navigating to bilbo’s home directory.

  1. You can always exit from bilbo and return to your current user by running the exit command. For the moment, remain as bilbo.
  2. Now, let’s change the bilbo's password; we will use the passwd command.
$ sudo passwd bilbo
[sudo] password for bilbo: # Type in the default password
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

🚨 Your password is again hidden.

  1. Let’s create a new user called frodo; his password is sting. Go on and create a new user.

You might need to go back ⬆️ to step 42.

  1. We can see the folders created in the home directory using the following command.

There might be a few user home directories there, 🚨 note that user ubuntu is a sudoer, and it is a default created.

$ ls /home
... bilbo    frodo   ... ubuntu ...
  1. I will delete user frodo 🙅 ; I will need to run the following command for this action.
$ sudo userdel frodo
  1. Let's check once more the folders in the home directory.
$ ls /home
... bilbo    frodo   ... ubuntu ...

🚨 Mmm.. deleting a user does not necessarily remove the user's home folder.

  1. Let's delete it.
$ rm -rf /home/frodo
rm: cannot remove '/home/frodo/.bash_logout': Permission denied
rm: cannot remove '/home/frodo/.profile': Permission denied
rm: cannot remove '/home/frodo/.bashrc': Permission denied

🚨 We cannot delete it! Except if we are a sudo!

Permission denied signifies that the folder belongs to frodo and not to bilbo.

  1. Apparently, we need to be a sudoer to run such commands to force deletion of the folders belonging to other users. Try the following command.
$ sudo rm -rf /home/frodo

Now the folder is gone!

  1. Let's validate our assumptions.
$ ls /home
... bilbo ... ubuntu ...
  1. Let’s summarize the commands that need **sudoer** privileges

    • sudo command → Runs a command as a superuser

    • adduser frodo → Creates a new user `frodo``

    • ``usermod -aG sudo frodo→ Makesfrodo` a superuser

    • su - frodo → Switch between users, by navigating into their home directory

    • passwd frodo → Change frodo's password.

    • userdel frodo → Deletes frodo, but not frodo's home directory

  2. The following command changes the user privileges from sudo to non-sudo user, in other words, it downgrades an account privilege.

$ sudo gpasswd -d username sudo

Make sure that you always have access to a superuser account before downgrading or deleting other accounts.

🚨 Linux operating system allows you to remove sudo access from an account that you are already logged in to. If you have only one sudo account and you downgrade its privileges, you will lose superuser access to your system.

This means that your Linux system is now sudo locked making your system unusable (you cannot install delete etc. but you can list and manipulate only your files).

🏁 Well done! You completed parts 1 and 2, now do both one more time 💪