I see some of the users I can find under /home directory in centos but not rest of the users.

Users that are listed under /home directory, I can login as those users with command

su username

To find rest of the users, I had to use the command:

cut -d: -f1 /etc/passwd

To login as one of these rest of the users, I need to use command

sudo -u username

what is the difference?

  • Can you really log in as all those users with sudo -u <username>? – garethTheRed May 21 '16 at 13:55
  • Not exactly login but could perform the actions limited to those users. – Simran kaur May 21 '16 at 13:57

If you run a similar command to yours:

$ cut -d: -f1,6,7 /etc/passwd

you will notice that the only accounts with a /home directory are the ones where a) the second column above has a path to a directory within /home, and b) have a shell in the third column (/bin/bash).

All the other users cannot log in as they either have a shell of /sbin/nologin, which as the name implies doesn't allow login, or have a shell that is a specific command, such as /sbin/halt.

You can run commands as the other users, or even run a shell:

$ sudo -u daemon whoami
$ sudo -u daemon bash
$ whoami
$ echo $HOME

but you won't have a home directory within /home.

More importantly, you can't log in at a login prompt or with su or ssh on these accounts because the shell is /sbin/nologin and their passwords will have been disabled (look for a !! or a * in the 2nd column of sudo less /etc/shadow).

These accounts are all system accounts used by services such as email or dhcp or used to shutdown the system.

You shouldn't really be running commands as these users using sudo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.