By examining the first, third and last (seventh) fields of the /etc/passwd file, determine the userid and login shell for your username, the user root, and the user nobody (yes, there is a system user with the username "nobody"). Create simple files in your home directory, called my.uid, my.shell, root.uid, root.shell, nobody.uid, and nobody.shell, which contain only the appropriate information on a single line.

For example, if the user nobody's login shell were /bin/bash, the following command would easily create the appropriate file.

[student@station student]$ echo /bin/bash > nobody.shell
[student@station student]$ cat nobody.shell
/bin/bash

I don't know how to find the UID because when I opened the passwd file the first was root, but the third and seventh fields were completely different. Any help?

Dani AI

Generated

Quick clarification for and follow-up to : /etc/passwd is a colon-separated file. The fields are

username:password:UID:GID:GECOS:home:shell

so the third field is the numeric UID and the seventh field is the login shell. The confusion in the original post usually comes from looking for "columns" separated by spaces rather than colons.

Practical, copy-paste friendly commands (create the six files in the home directory):

# robust (works with NSS: files, LDAP, NIS)
id -u > ~/my.uid
getent passwd "$USER" | cut -d: -f7 > ~/my.shell

getent passwd root   | cut -d: -f3 > ~/root.uid
getent passwd root   | cut -d: -f7 > ~/root.shell

getent passwd nobody | cut -d: -f3 > ~/nobody.uid
getent passwd nobody | cut -d: -f7 > ~/nobody.shell

If getent is not available, use the /etc/passwd fallback:

grep -E "^${USER}:" /etc/passwd | cut -d: -f3 > ~/my.uid
grep -E "^${USER}:" /etc/passwd | cut -d: -f7 > ~/my.shell
# repeat for root and nobody (replace ${USER} with root or nobody)

Notes and cautions: root always has UID 0; the UID for nobody varies between distributions (commonly a high number such as 65534 on many Linux systems, but not guaranteed). Many system accounts use noninteractive shells such as /sbin/nologin or /bin/false, so a shell entry does not always mean an interactive login is allowed. If an account is managed by a central service, getent will show it while /etc/passwd may not. The created files live in the home directory and contain a single line each; check them with any pager or editor and set permissions if sensitive information must be restricted.

Hello,

The UID is the user id and it is stored in the /etc/passwd file. Below is a link to a site the explains the format of the date in the file:
http://en.wikipedia.org/wiki/Passwd

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.