Linux Commands - useradd (create a user account)

The useradd command can be used to create a users account in Linux.


Create user

The useradd command followed by username can be used to create a user account.

~]# useradd john.doe

 


Change password

The -p or --password option and OpenSSL can be used to create an encrypted password for the user.

useradd --password "$(openssl passwd -1 itsasecret)" john.doe

 

Or, more commonly, the passwd command is used after the users account has been created.

passwd john.doe

 


Create home directory

The -m or --create-home or -d or --home-dir options can be used to create the users home directory. In this example, the home directory is /home/john.doe.

useradd --home-dir /home/john.doe john.doe

 


Create default shell

The -s or --shell option can be used to create the users default shell (/bin/bash in this example).

useradd --shell /bin/bash john.doe

 


Join a group

The -G or --groups option can be used to add a new user to a group. In this example, john.doe is added to the group named "wheel".

useradd --groups wheel john.doe

 


Add comment

The -c option can be used to add a comment. The comment is typically the users first and last name.

~]# useradd -c "John Doe" john.doe

 


View users account

The /etc/passwd file will contain the users account. Refer to Linux Files - Understanding the /etc/passwd file to view the users account.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 14e52 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |