Adding Users with useradd
You need to add new users to a Linux system.
Use useradd -m to create a login name, home directory, and other environment variables, and use the passwd -e command to set the new password. The account is not active until you create a password.
This is the simplest invocation. The -m flag creates a home directory and copies in the files from /etc/skel:
# useradd -m
newusername
Under most circumstances, you should also specify the user's full name, using the -c (comments) flag. Put four commas after the user's name, to leave other parts of the comments field (office number, etc.) blank.
# useradd -m -c Grace Hopper,,,, ghopper
When adding a new user, newusername becomes the user's login name. This must be a unique name.
Next, run passwd -e. The -e flag expires the password at first login, forcing the user to change it:
# passwd -e ghopper
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
The user's environment is created according to the defaults in /etc/default/useradd and /etc/skel/. You can display the useradd defaults:
# useradd -D
Any of the default values can be overridden at the command line—for example, the UID and shell:
# useradd -u 1500 -s tcsh ghopper
Or you can add to the default values—for example, adding additional group memberships:
# useradd -G users,cdrecord,dialout ghopper
You need to add new users to a Linux system.
Use useradd -m to create a login name, home directory, and other environment variables, and use the passwd -e command to set the new password. The account is not active until you create a password.
This is the simplest invocation. The -m flag creates a home directory and copies in the files from /etc/skel:
# useradd -m
newusername
Under most circumstances, you should also specify the user's full name, using the -c (comments) flag. Put four commas after the user's name, to leave other parts of the comments field (office number, etc.) blank.
# useradd -m -c Grace Hopper,,,, ghopper
When adding a new user, newusername becomes the user's login name. This must be a unique name.
Next, run passwd -e. The -e flag expires the password at first login, forcing the user to change it:
# passwd -e ghopper
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
The user's environment is created according to the defaults in /etc/default/useradd and /etc/skel/. You can display the useradd defaults:
# useradd -D
Any of the default values can be overridden at the command line—for example, the UID and shell:
# useradd -u 1500 -s tcsh ghopper
Or you can add to the default values—for example, adding additional group memberships:
# useradd -G users,cdrecord,dialout ghopper
0 Comments