.run any command as root, after providing the root password.run certain commands as the root user. Aug 02, 2017 The permission on the /etc/passwd file should be read only to users (-rw-r–r–) and the owner must be root: $ ls -l /etc/passwd Sample outputs:-rw-r-r- 1 root root 2659 Sep 17 01:46 /etc/passwd Reading /etc/passwd file. You can read /etc/passwd file using the while loop and IFS separator as follows.
I have a question similar to another one on this site where the individual had to find a list of all users using grep or awk from /etc/passwd. That worked for me but I've tried translating it to find and list the home directories of them also. I already know you can't do it in one line so I know I would use a pipeline.
I've done my research online but I can't figure it out the problem is. If I use grep and do something like the following: grep -oE '^/./$' /etc/passwd.i t would probably give me an error or it will also show me the /bin/bash files which is not what I want.
I just need the user names and their home directories listed using grep! I'm also not sure if the. will show other forward-slashes as characters, as some home directories have more than just two /'s (forward-slashes).
As others have pointed out, grep isn't the best tool for this. If you insist on using it, and if your grep supports the -o (only print the matched portion of the line) and -P (use Perl Compatible Regular Expressions), you can do this: $ grep -oP '^^:+.:K^:+(?=:^:+)' /etc/passwordterdon/home/terdonbob/home/bobNote that this will print all users, including system users. I am only showing 4 lines as an example.That will print the user name and home directories of all users but on separate lines.
The problem may be an incorrect line in the passwd file anywhere above the lineon which the user is listed. In this case, the passwd file entry 10 lines abovewas missing a colon.
Replacing that colon fixed the problem.To determine WHERE in the passwd file the problem is, make copies of both thepasswd and shadow files, then enterpwconvThen, when you look at the passwd file, you will see that the line with theproblemand all lines below that point will be missing. Now, of course, you'll have tocopy back the original passwd and shadow files, but you'll know what line thesyntax error is on.And just from looking at your output, you are missing smtp from the shadow file.