Linux Command 11 – useradd, userdel, usermod, groupadd, last, lastb
1) useradd = create a new user or updates default new user information
Usage:
useradd login options
Examples:
# useradd usr1 — Add new user usr1 with default settings
# useradd usr1 -d /home/usr1 — Create the new user’s home dir in /home
# useradd usr1 -e 2009-04-30 — From 30/4/2009 the user acc will be disabled.
# useradd usr1 -f 6 — After passwd expires, system will allow the user to login for 6 days with a warning to change his passwd.
# useradd usr1 -g staff — Set user1 group as staff
# useradd usr1 -p $1$d8 — Create the usr1 with the given encrypted password. For No passwd, acc disabled.
# useradd usr1 -s /bin/csh — Set C Shell as the default login shell for the usr1
.
2) userdel = delete a user account and user’s related files
userdel loginname – delete the user account
userdel -r loginname – delete the user account together with user’s home directory and all files inside it
userdel -f loginname – for the deletion even the user is still log in, it will force to delete the user’s home directory and files as well, this option is dangerous use with caution
.
3) usermod = to modify a users account
Examples:
# usermod -d /home2/usr1 usr1 — Create the new home Dir for usr1 in /home2 & Move old Dir contents to this Dir.
# usermod -e 2005-04-30 usr1 — From 30/4/2005 the usr1 acc will be disabled.
# usermod -f 6 usr1 — After passwd expires, system will allow the user to login for 6 days with a warning to change his passwd.
# usermod -g prof usr1 — Set usr1’s initial group as prof.
# usermod -p $1$d8 usr1 — Set the new passwd for the usr1
# usermod -s /bin/bash usr1 — Set Bash as the default login shell for the usr1.
# usermod -L usr1 — Lock a user’s password.
# usermod -U usr1 — Unlock a user’s password.
.
4) groupadd = create a new group
# groupadd sales
.
5) last = show listing of last logged in users
Examples:
$ last — List all entries.
$ last tty6 — List, who are all logged thru tty6.
$ last bharathi — List all entries of bharathi (user).
$ last -6 — List only last 6 entries.
$ last -R — Don’t show the Host Name field in output.
$ last -a — Show Host Name field in last column.
$ last -i — Show IP Number for Remote host.
$ last -t 20080818120000 — List all entries upto Aug 18 12:00:00 2008
.
6) lastb = display a list of recent bad login attempts (from the /var/log/btmp file). Accepts the same option flags and arguments as last
Fuente: https://linuxfrombeginning.wordpress.com/2008/09/27/linux-command-11-useradd-userdel-usermod-groupadd-last-lastb/