SOHO : Small Office Home Office
Freeware - Opensource software tips, tricks, tweaks & fixes for managing, securing, improving the performance of SOHO Desktop, Laptop, Networks

Monday, March 19, 2012

How to add & remove users by command line in ubuntu?

To add a user you must use be root or use the sudo command. Here are the commands:

To add a user. NOTE: do not use the useradd command.
$ sudo adduser <username>


To see the options for adding a user try the man command.
$ man adduser


Add user
Here is a useful example of the useradd command. Why use useradd? It gives a few more options for special cases. To add a user, give her a standard home directory in the /home folder and specify the shell she accesses by default do this:

$ sudo useradd username -m -s /bin/bash 
$ sudo passwd username 

Groups


You might also wish to create a new group for your users.
# sudo addgroup <groupname>


To add a new user to a existing group you would do this:
# sudo adduser <username> audio


To add an existing user to an existing group you can use the same command:
# sudo adduser <username> <groupname>

or
# sudo usermod -aG <groupname> <username>



Delete  user

To remove a user from a system without deleting the users home directory.
# sudo userdel username


To remove the user and delete the users home folder:
# sudo userdel -r username


1 comment:

  1. Nice! If you want to learn how to create and delete users on Ubuntu Server using useradd and userdel commands and also to check the new user values you can take a look at Create and delete users on Ubuntu Server (video tutorial).

    ReplyDelete