User maintenance

Most Linux distributions for the Banana Pi come preconfigured with a default username and password. The login information is published on the download website for the operating system images (see Chapter 1, Installation and Setup).

In almost all cases, the credentials are:

Username

Password

bananapi

bananapi

You might want to create your own user on the system. At the very least, it is highly recommended you change the default password of the default user. This recipe explains the necessary tasks.

Getting ready

The following ingredients are required to create or delete users and to change their passwords:

  • A booted up Linux operating system on your Banana Pi
  • SSH connection if you plan to do the user maintenance remotely; however, in most of the upcoming recipes, you can do the user maintenance directly on Banana Pi

How to do it…

We will split this recipe into adding a user, changing a password, and deleting a user.

Adding a new user

We are going to use the useradd and the passwd commands to add a new user with the name alice and the password wonderland. Choose any other name and password as you wish.

  1. Connect to your Banana Pi remotely or open a terminal on the desktop.
  2. Type in the following command to add a new user alice:
    $ sudo useradd -m -s /bin/bash alice
    
  3. If you are requested to type the password for sudo, enter the default password, that is, bananapi.
  4. Now, we want to add the new user to all the groups that the default user is a member of. To do so, we have to find out the groups of our default user:
    $ groups
    
  5. We get a list of all groups of the bananapi user. To assign alice to these groups, we use the following command:
    $ sudo usermod -a -G pi,adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,netdev,input,indiecity,spi,gpio alice
    

    Keep in mind, that the groups are separated by a comma and not a space. Also note that depending on your distribution, the list of groups may differ.

You have just created a new user name alice and assigned the user to all groups that the default bananapi user is a member of.

Setting a password for a user

Now we are setting a password for our new user alice:

  1. Type the following command to give the new user a password:
    $ sudo passwd alice
    
  2. You will be requested to type the desired password. Enter the password wonderland.
  3. Repeat the password wonderland.
  4. The command will reply with: passwd: password updated successfully.

You have assigned the password wonderland to the user alice. Take a look at the following screenshot:

Setting a password for a user

In the preceding screenshot, you see the adding of the user, the group assignment, and the password assignment of the user alice.

Deleting a user

To delete the previously created user, we use the userdel command:

  1. Type the following command into a shell to delete the user alice:
    $ sudo userdel alice
    
  2. If you are requested to enter a password for sudo, use the default password bananapi

You have successfully deleted the user alice.

How it works…

Linux and other Unix-like operating systems are so-called multiuser systems. The name implies that these systems are able to handle more than one user simultaneously. Each user has its very own place where their files and configurations belong, the so-called home directory (often abbreviated as ~).

Most user modifications require root privileges. Therefore, we prefix every command with sudo.

We are adding a new user by executing the useradd command. This command takes some parameters. The -m parameter will tell useradd to create the home directory automatically (/home/alice in our case). As the new user wants to be able to log in, we have to set a default shell, which is done by -s followed by the full path to the shell (the path to Bash in our example). Last but not least, the user must have a name, which is alice in our previous case.

Also, a user can be assigned to different groups, which have different permissions for various tasks. To find out which groups are assigned to the default user, we are using the groups command. When executed, it outputs all groups of the current user (that is bananapi). We assign the same groups to our user alice by using the usermod (user modify) command. The usermod command modifies information about a user, -a in combination with -G adds the user to a so-called supplementary group, which is given as a comma-separated list.

Since each user should have a password, we assign a password by using the passwd command. You can also change the password of the default user bananapi this way.

Finally, if we want to delete a user, we simply issue the userdel command.

There's more…

If you delete a user by the userdel command, the user's home directory will remain untouched. Thus, if you also want to delete their whole home directory, you will need to use the rm (remove) command forcing (-f) and recursive (-r):

$ sudo rm -rf /home/alice

Note

The rm -rf command will remove the whole directory that you issued without any confirmation. So use that command with absolute care, as you can easily remove the wrong folder or even destroy the system!

Another interesting command is the id command. It provides additional information such as user ID (uid) and the user's associated group IDs (gid). The following screenshot shows group information for the user alice by issuing the id command:

There's more…

See also

  • A helpful article about user and group management in Arch Linux, which is also usable for most other distributions is available at https://wiki.archlinux.org/index.php/Users_and_groups
  • Manual pages of useradd, passwd, usermod, userdel, id, and groups; for example:
    $ man useradd
    

    Each manual page contains informative material about these commands.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.195.128