Useful Commands for User Administration in Linux


The following commands are commonly used for system administrators to manage users.

1. To create a user account with specific home directory and user ID
# useradd 'user' -d 'home_dir' -u 'uid'

2. To lock a user's account
# passwd -l 'user'
# chmod 000 /lhome/'user'/.ssh

3. To unlock a user's account
# passwd -u 'user'
# chmod 700 /lhome/'user'/.ssh

4. To check which users are connected to your server
# w
# who

5. To terminate a user's connection to your server (be cautious!!!)
# skill -KILL -u 'user'

6. To disconnect a user from your server
# skill -STOP -u 'user'

7. To reconnect a user to your server
# skill -CONT -u 'user'

8. To remote login a host with key (without password)
a) generate a key for your account in ~/.ssh if it is missing (leave each prompt input empty)
# ssh-keygen -t rsa
b) copy the key to the remote host
# ssh-copy-id 'user'@'host'

9. To set password in one command line
# echo -e 'passwd\npasswd' | passwd 'user'
Or # echo -e 'passwd' | passwd --stdin 'user'