Create, delete, and modify local user accounts

Adding a user account

Use the useradd command to add new user :
# useradd [options] [username]
The default settings for new user can viewed and modified using the -D option :
# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
For example, to change the default user shell for new user to /bin/ksh :
# useradd -D -s /bin/ksh

Examples

To simple add a user with all default options :
# useradd user01
To add user with uid 1099, comment “new user” and default shell as /bin/ksh :
# useradd -u 1099 -c "new user" -s /bin/ksh user01
Check new user’s entry in /etc/passwd file :
grep user01 /etc/passwd
user01:x:1099:1099:new user:/home/user01:/bin/ksh
To modify existing user (e.g. changing the comment) :
# usermod -c "modified user" user01
To assign the password to new user:
# passwd user01
Changing password for user user01.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
View the /etc/shadow file :
# grep user01 /etc/shadow
user01:$6$dox84xyJ$89DdMcxSlI9OHxUCyY1ryaFsmG6MSEwbmSbZXJoFY.tHgdEEeQQgQjDV0dD8jEiHusrUjj3p8gtMTKR4sXXN5.:17058:0:45:7:::
To delete the user :
# userdel user01

nologin shell

You can create a user with nologin shell for running services such as SMTP, FTP etc. A user without a login shell can not login to a system and therefore cannot run any command on the system interactively on the system. Processes can run as that users however.
To add new user “test” with shell nologin :
# useradd -s /sbin/nologin test
Make sure the nologin shell is present in the /etc/shells file :


# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin

0 comments:

Post a Comment