Users in GNU Linux

Table of Contents

User management in GNU/Linux

List all the existing users

$ cat /etc/passwd

Add new user

  1. Add username first

    $ sudo useradd username
    
  2. Add password

    $ sudo passwd username
    

    This will not create home directory “/home/username” to do that

  3. Create user with home directory

    $ sudo useradd -m username
    

    Followed with passwd creation as above mentioned.

  4. Adding home/directory after creating user

/home/Android/Sdk

$ mkhomedir_helper username
```

Changing the shell of user

$ grep username /etc/passwd

--> username:x:1003:1003::/home/username:/bin/sh

Here the user has “/bin/sh” as shell.

Changing it to Bash.

$ usermod --shell /bin/bash username

Login with new user

$ su - username 

Enter the user password and login.

Removing the user

$ sudo deluser --remove-home eric

Error:

While logging into new account ls, cat, clear the basic commands were not working. On Root it was working but not in new user.

Solution:

  1. Have a root access.
$ su
$ root@host$ 
  1. Update the .bashrc file on other user (newuser)

cd into

root$ cd /home/newuser

Open .bashrc file of newuser

root$ nano .bashrc

Add this

export PATH="$PATH:/bin"
export PATH="$PATH:/usr/bin"
  1. Login to newuser
root$ su - newuser
## Enter password
  1. Update the source file
newuser# source ~/.bashrc
  1. Wolaah! commands should work now.
Tags :