Users and Passwords

Lesson Requirements

The sudo user

Have you ever played a game where you had to be a really important character, like a king or a queen? When you’re playing that game, you have special powers that let you do things that other characters can’t do, like make big decisions or give orders to other characters.

Well, in a computer, there’s a program called “sudo” that’s a little bit like being the king or queen of the computer. When you use the “sudo” program, it gives you special powers that let you do things on the computer that regular users can’t do.

In Linux, the “sudo” command stands for “superuser do.” It’s a way to temporarily become the most powerful user on the computer, known as the “root” user. When you use “sudo,” you can do things on the computer that regular users can’t do, like installing software, changing system settings, and accessing important files.

For example, let’s say you want to install a new program on your Linux computer. Normally, regular users don’t have permission to install software. But if you use “sudo” with the “apt-get” command like this:

sudo apt-get install firefox

You’ll be able to install the Firefox web browser on your computer!

Here are some other examples of Linux commands that use “sudo”:

  1. sudo apt-get update : This command updates the list of available software packages on your computer.
  2. sudo apt-get upgrade : This command upgrades any software packages that have updates available.

Remember, using “sudo” can be very powerful, so it’s important to use it carefully and only when you need to do something that requires superuser permissions.

Passwords

The passwd file in Linux is like a special list of usernames and passwords that the computer uses to let people access it.

For example, let’s say that our Linux computer has two users, Alice and Bob. Each user has their own password that only they know. The passwd file would contain a line for each user that looks something like this:

alice:x:1000:1000:Alice:/home/alice:/bin/bash
bob:x:1001:1001:Bob:/home/bob:/bin/bash

The first part before the colon is the username (alice or bob). The second part is a special code that represents the password, but it’s not actually the password itself (that’s kept secret and encrypted). The next two numbers (1000 and 1001) are called user IDs and are used by the computer to keep track of who owns which files. The next part (Alice or Bob) is just the person’s full name. The part after that (/home/alice or /home/bob) is the location of their personal folder on the computer, where they can store their own files. And the last part (/bin/bash) is the program that runs when they log in and lets them type commands into the computer.

So, the passwd file is a very important file in Linux that helps the computer keep track of who is allowed to access it and what they can do. Only people who know their own password can log in to the computer and use it.

The passwd command is a tool used in Linux operating systems to change your password. You can think of it as a key that locks and unlocks your computer account. When you first create your account, you set a password to keep your account secure. The “passwd” command lets you change that password at any time.

This will prompt you to enter your current password and then to enter a new password twice. Make sure to choose a strong password that’s difficult for others to guess.

Once you’ve entered the new password twice, the computer will update your account information to use the new password. You can now use the new password to log into your account.

It’s important to change your password regularly and to use a strong password that’s difficult for others to guess. This can help keep your account secure and protect your personal information.

Activity: Updating Password File

Modify a user’s password by opening the “passwd” file in a text editor, locating the user’s line, changing their password field, and saving the file.

Activity: Changing User Password

Change the password for a user by entering passwd followed by the username and typing in a new password twice when prompted.

Creating Users

On Ubuntu, the adduser command is used to create new user accounts. Here’s how it works:

The basic syntax for the adduser command is as follows:

sudo adduser username
  • “sudo” is used to run the command with administrative privileges, which are required to create a new user account.

  • “username” is the name you want to give the new user. You can choose any name you like, as long as it’s not already in use on your system.

Here are some examples of how to use the adduser command:

Create a new user with a specific password:

sudo adduser john

This will create a new user account named “john” and prompt you to set a password for the account.

Create a new user with additional information:

sudo adduser jane --gecos "Jane Doe,123-456-7890, jdoe@example.com"

This will create a new user account named “jane” and prompt you to set a password for the account. The “—gecos” option allows you to provide additional information about the user, such as their full name, phone number, and email address.

Activity: Delete a User

Add a new user to the system by typing “adduser” followed by the desired username, and follow the prompts to set a password and additional user information.

Deleting Users

The deluser command is a special command in Linux that helps us delete a user account from the computer. It’s like erasing a person’s name from a list of people who are allowed to use the computer.

For example, let’s say that we want to delete the user account for a person named Alice from our Linux computer. We can use the deluser command like this:

sudo deluser alice

We might need to enter a password first. The “deluser” part is the command we want to use, and “alice” is the name of the user account we want to delete.

When we run this command, the computer will delete Alice’s account and all of her personal files and settings. This means that she won’t be able to log in to the computer anymore, and all of her files will be gone forever.

It’s important to be careful when using the deluser command, because once we delete an account, we can’t get it back! So we should only use this command if we’re absolutely sure we want to delete the account.

Activity: Create A User

Remove a user from the system by typing “deluser” followed by the username of the user to be deleted.

Putting It All Together

  1. Use the adduser command to create a new user with a secure password.
  2. Use the passwd command to change the password for an existing user to a different secure password.
  3. Open the passwd file in a text editor and locate the line for the user whose password you changed earlier. Verify that the password field has been updated.
  4. Use the deluser command to delete the user you created earlier.

Vocabulary Review

  • sudo
  • adduser
  • deluser
  • passwd command
  • passwd file