3

I'm a software dev suddenly finding myself having to play SysAdmin.

Recently, I was given a box previously administered by somebody else, and this SysAdmin kind of just did what he wanted. My supervisor is given the box to SysAdmin, and it appears that the home directories for users are hidden everywhere in the box.

Needless to say, the answer to his problem is "hey intern!"

So, I was wondering if there was a way to find all of the home directories for all of the users on the box? The box I'm working on is RHEL 5.

slm
  • 7,355
  • 16
  • 54
  • 72
eskaife
  • 133
  • 4

2 Answers2

7

Assuming all the users are local users (that is, there's no network directory service like LDAP, Active Directory, NIS, etc), then local users are probably all enumerated in /etc/passwd, which is a colon delimited file with the following fields:

username:password:uid:gid:name:home directory:shell

You can get just the usernames and home directories, if that's easier, like this:

awk -F: '{print $1,$6}' /etc/passwd

Using Urgoll's suggestion of using the getent command, that's:

getent passwd | awk -F: '{print $1,$6}'
larsks
  • 41,276
  • 13
  • 117
  • 170
  • Even if the box uses ldap, active directory, NIS or whatever, your answer is mostly correct. The following command will output the aggregated content of all passwd sources and can be manipulated with awk: `getent passwd` – Urgoll Jul 31 '13 at 21:14
  • 1
    ...except it won't, in some cases. Many backend directories implement a limit on result size of any query, so `getent` in some cases cannot enumerate all the available users. But for smaller environments, yeah, that works. – larsks Jul 31 '13 at 21:16
1

You're in luck! Everything you want in /etc/passwd :-)

For example:

jay:x:1000:1000:Jay Shah,,,:/home/jay:/bin/bash

Where jay is my username, 1000 is my uid/gid, /home/jay is my home directory, and /bin/bash is my shell.

Jay
  • 6,439
  • 24
  • 34