Q. How do I add a new user using command line tools? What are command line option recommended.
A. You need to use useradd command, which is responsible for creating a new user or update default new user information
The useradd command creates a new user account using the values specified on the command line and the default values from the system. The new user account will be entered into the system files (/etc/passwd) as needed, the home directory (/home/username) will be created, and initial files copied, depending on the command line options.
Task: Add a user to the system
Syntax is as follows for useradd command:
useradd <username>
By default user account is locaked, you need to setup a new password:
passwd <username>
For example add a new user called tom and set password to jerry:
# adduser tom
# passwd tom
If you want to add a user to group read how to add a user user to group
List of common options:
- -c comment: Add a comment for the user
- -d home-directory: Create a new home-directory
- -e yyyy-mm-dd: Date for the account to be disabled
- -f days: Number of days after the password expires until the account is disabled. (If 0 is specified, the account is disabled immediately after the password expires. If -1 is specified, the account is not be disabled after the password expires.)
- -g group-name: Primary Group name or group number for the user’s default group (group name must exist)
- -G group-list: List of secondary additional (other than default) group names or group numbers, separated by commas, of which the user is a member (group name must exist)
- -m: Create the home directory
- -M: Do not create the home directory
- -s: User’s login shell (default /bin/bash)
To read all command line option type following command:
$ man adduser
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 29 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
thanks for your information.
Thank you
how do you set limits such as disk quota ?
For example add a new user called tom and set password to jerry:
# adduser tom
# passwd tom
passwd in example should be:
# passwd jerry
Its actually
useradd or adduser tom
passwd tom
The following prompt will come up after you input “passwd tom” than type jerry
New UNIX password: jerry
Do you even linux?
Actually the example is right because as soon as you type the username after the password the command line prompts you to enter the new password and then prompts you to do the same. And anyways how is it supposed to know which username’s password to change?
Use the command called ‘quota’ to set limits for disk usage.
hi please how can i change the acces pasword the ftp server ton enter in my server ebrunie-voip?
i wont to change the access to protect my server agains some fraud.
thank
panye
i was looking for differences between ‘useradd’ and ‘adduser’, but you seem to mix both….
see this:you first talk about useradd, then you put an example with adduser !
How can i manage user from Command Line
Let suppose i create user spiderman and grant Superuser like root!
Is it possible to create user and password in single cmd?
useradd -m user1 -p passwordforuser1
Be sure to man useradd as there are a bunch of other options that this article leaves out like adding keys, names, passwords, and other things. man is your friend learn to use it or you will hate life in linux/unix
I am still a bit new to UNIX but yours sounds like probably the best advice here… about man most definitely.
On a side note… and this is just a shot in the dark. I am trying to get an Ubuntu 10.04 box, which has been upgraded and updated as of 11/2012, to run Teamspeak and a game called ArmA 2. The game has a modification called @ACRE that enhances Teamspeak. I have the Teamspeak server running and can get to it through my WAN IP. I have the mod loaded in the game server. I have the same mod loaded in the Windows client. The Teamspeak server never recognizes the the mod is loaded in the game.
Again, I know this is a shot in the dark but maybe you know about this game or maybe you have some general suggestions.
Anyway, thanks again for the good advice.
What would you type at a command line to create a new user called “Susan”, but not create a password? (Susan will not be able to use her account until you set one)
Hello, thanks for the information, but the real question is if u want to create or give an user admin rights or root rights how do you do it…. ?
thanks for giving the information about useradd but how do we can make user as a group
I know I’m late to the party but to allow a user to run root commands,
you can do a couple things…
A) add the user’s numeric If to the root group in /etc/group
This is a single file but it doesn’t guarantee all root access.
B) add them to the /etc/sudoers file.
You need to be root to do it.
su as root, change the permissions on /etc/sudoers to 600 then vi/nano it. After looking through the file to see the format you need to use to add the user, save the file, change the perms back to 400 (I think it was 400) otherwise sudo won’t work for the user.
Now whenever you log in as that user, you can type in sudo and you’ll have root permissions.
Easy as Pi
– Ace Macleod –
too late nerd haha
hi ,
how about add user full name
how to create mail id for a particular user in putty server? and already i had added user name and password,after that how to proceed?
WoW ! nice article i got it here. Thanks for sharing this information on your blog.
The command used to send the message to all users who logged or not logged in.
how to su user basic to root permision
Hmm… this appears simple, but for me it’s not working. I tried it like this:
adduser -d
But it doesn’t create anything, just lists the option. Trying to set a password confirms the username doesn’t exist. I’m a total n00b, basically just following a tutorial for installing Arch, so any ideas ?
No
You should explain the difference between useradd and adduser when you use both…
useradd is the system binary, adduser is a Perl script that simplifies some things.
Unable to add user. The error is only root may add user or group to the system.
can anyone explain how to resolve this.?
if i’m adding an user the system say “/etc/passwd” denied why
you need root access