Email This List Email This List Print This List Print This List

Adding a New User

Adding a New User

 

Debian/​Ubuntu

  1. Open a ter­min­al win­dow and log into your Linux serv­er with Putty.
  2. Cre­ate the user by enter­ing the fol­low­ing com­mand. Replace exampleuser with your desired user­name:
    1
    adduser exampleuser
    
  3. Add the user to the admin­is­ter the sys­tem (admin) group by enter­ing the fol­low­ing com­mand. Replace exampleuser with your user­name:
    1
    usermod -a -G sudo exampleuser
    
  4. Log out of your serv­er as the root user by enter­ing the fol­low­ing com­mand:
    1
    logout
    
  5. Log in to your serv­er as the new user by enter­ing the fol­low­ing com­mand. Replaceexampleuser with your user­name, and the example IP address with your serv­er IP address:
    1
    ssh exampleuser@123.456.78.90
    

CentOS/​Fedora

  1. Open a ter­min­al win­dow and log in via SSH.
  2. Cre­ate the user by enter­ing the fol­low­ing com­mand. Replace exampleuser with your desired user­name:
    1
    adduser exampleuser
    
  3. Set the pass­word for your new user by enter­ing the fol­low­ing com­mand. Replaceexampleuser with your desired user­name:
    1
    passwd exampleuser
    
  4. You will now need to edit your sudo­ers file to grant your new user the cor­rect per­mis­sions. Enter the fol­low­ing com­mand to open your sudo­ers file for edit­ing:
    1
    visudo
    
  5. Type ‘i’ to enter the insert mode, and add an entry for your user below the root user, grant­ing all per­mis­sions. Replace exampleuser with your user­name:
    1
    2
    3
    ## Allow root to run any commands anywhere
    root    ALL=(ALL)       ALL
    exampleuser        ALL=(ALL)       ALL
    
  6. Press ‘Esc’ to leave insert mode and enter the fol­low­ing com­mand to save the file and quit visudo:
    1
    :wq
    
  7. Log out of your serv­er as the root user by enter­ing the fol­low­ing com­mand:
    1
    logout
    
  8. Log in to your serv­er as the new user by enter­ing the fol­low­ing com­mand. Replaceexampleuser with your user­name, and the example IP address with your serv­er IP address:
    1
    ssh exampleuser@123.456.78.90
    

Now you can admin­is­ter your serv­er with the new user account instead of root. When you need to execute super­user com­mands in the future, pre­face them with sudo. For example, later in this guide you’ll execute sudo iptables -L while logged in with your new account. Nearly all super­user com­mands can be executed with sudo, and all com­mands executed with sudo will be logged to/var/log/auth.log.

Related Post

admin has written 133 articles