Notes on Unix and Linux user admin such as managing users and groups.

Users and Groups

create a new user

useradd -m -s /bin/bash -U -G <groups> USER_NAME

-m: create new home directory
-s <SHELL> : assign default shell
    * use `/usr/sbin/nologin`
-U: create group with same username
-G <GROUPS>: add to groups (comma separated)
    * add 'sudo' if needed


useradd -m -s /bin/bash -U -G adm,cdrom,sudo,audio,video,users,i2c johndoe

add user to other groups

# usermod -a -G <GROUPS> <USER>
# usermod -a -G ftp,sudo   johndoe

change user’s default shell

# usermod -s <SHELL> <USER>

Or use cshs as a user

chsh -s $(which zsh)

disable login by changing shell

# usermod -s /usr/sbin/nologin

create a new user (Debian only), easy version of useradd.

# adduser <USER> <GROUP>

/etc/adduser.conf : Default configuration for new users.

create group (Debian only), easy version of groupadd.

# addgroup <GROUP>

Login as another user



change password

passwd [<USER>] 

# change my password

# change someone else's password
sudo passwd johndoe

view password status

passwd -S  #not in BSD

See man passwd for more , such as locking, unlocking, disabling, expiring

Special files

/etc/passwd: contains user’s name and shell.


<username>:<encrypted password>:<UID>:<GID>:<fullname>:<homedir>
  • <UID> : unique # identifying a user. Adduser will generate unique #.
  • <GID> : group that the user belongs to. Every user belongs to at least one group. To belong to more than 1 group, use ‘/etc/group’.

To disable account without deleting it, prepend * in password field. In Linux, it might be “!” instead of “*“. Also this can be done via passwd command


/etc/shadow: Encrypted user’s passwords. This corresponds exactly to /etc/passwd file.

/etc/group: Contains lists of all the groups and the user that belongs to that group.


<group name>:<password>:<GID>:<users>

  • <Password>: usually *.
  • <GID>: group id ie unique group #.
  • some groups are reserved for system like root, etc.
  • User may belong to more than 1 group.
  • addgroup, delgroup can be used but editing this file is easy.

Other Commands

deluser: Delete user (or userdel on some other system). To disable account, see ‘/etc/passwd’

ulimit : limits max processes per user

Monitor user activity

  • psacct
  • acct

TTY, Console, Who is logged in?

  • /dev/tty*: tty, native terminal device.
  • /dev/vcs* : virtual console, Linux only.
  • /dev/pts/* : SSH, Telnet (pseudo terminal slave)

tty or who or w :find out which tty/vcs/pts I am on.

$ tty

who : who was LAST logged on

$ who
vagrant  pts/0        2016-03-01 17:03 (

w: who’s currently logged on

$ w
18:00:11 up  1:02,  1 user,  load average: 0.00, 0.01, 0.01
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
vagrant  pts/0         17:03    0.00s  0.06s  0.00s w