Linux create new user
To create a new user in Linux, you can use the useradd
command. Here are the basic syntax and options:
Basic Syntax:
useradd [options] username
Options:
-m
or--create-home
: Create a home directory for the new user.-s
or--shell
: Specify the default shell for the new user.-g
or--group
: Specify the primary group for the new user.-G
or--groups
: Specify additional groups for the new user.-p
or--password
: Set the password for the new user.
Example:
useradd -m -s /bin/bash -g users newuser
This command creates a new user named newuser
with a home directory, sets the default shell to /bin/bash
, and assigns the user to the users
group.
Alternative Method:
You can also use the adduser
command, which is a more user-friendly alternative to useradd
. Here's an example:
adduser newuser
This command will prompt you to enter the password for the new user, and then create the user with default settings.
Additional Options:
-d
or--home-dir
: Specify a custom home directory for the new user.-c
or--comment
: Specify a custom comment for the new user.-e
or--expire-date
: Specify an expiration date for the new user's account.
Example with additional options:
useradd -m -s /bin/bash -g users -d /home/newuser -c "New User" -e 2023-12-31 newuser
This command creates a new user named newuser
with a home directory, sets the default shell to /bin/bash
, assigns the user to the users
group, specifies a custom home directory, sets a custom comment, and sets an expiration date for the account.
Remember to replace newuser
with the desired username, and adjust the options as needed for your specific use case.