Understanding /etc/passwd file in Linux

Linux has developed from being somebody’s interest to a full-fledged multi-user working system powering 95% servers which run world’s prime 1 million domains.

  • 4 out of 5 smartphones on this planet run on linux kernel(modified one to be exact).
  • 100% of the supercomputers have linux.

Linux is actually fascinating. On this weblog, we’ll perceive a few particular file in linux.

Let’s dive straight into it.

/and so on/passwd is a configuration file which shops consumer account info. It’s a plain text-based file containing info like username, consumer ID and group ID.

This file is owned by root and has rw-r–r– permissions(octal 644). Thus, the file could be learn by any consumer however solely root consumer or consumer with sudo privileges can write to the file.

To view the contents of the file, open the terminal and sort in:

cat /and so on/passwd
Enter fullscreen mode

Exit fullscreen mode

The output of this command needs to be just like the one proven beneath.

daniel@DVM:~$ cat /and so on/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
video games:x:5:60:video games:/usr/video games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
information:x:9:9:information:/var/spool/information:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
checklist:x:38:38:Mailing Listing Supervisor:/var/checklist:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
no one:x:65534:65534:no one:/nonexistent:/usr/sbin/nologin
systemd-network:x:100:102:systemd Community Administration,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/usr/sbin/nologin
syslog:x:104:110::/house/syslog:/usr/sbin/nologin
_apt:x:105:65534::/nonexistent:/usr/sbin/nologin
tss:x:106:111:TPM software program stack,,,:/var/lib/tpm:/bin/false
uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin
tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin
sshd:x:109:65534::/run/sshd:/usr/sbin/nologin
panorama:x:110:115::/var/lib/panorama:/usr/sbin/nologin
pollinate:x:111:1::/var/cache/pollinate:/bin/false
daniel:x:1000:1000:Daniel Tanzer,,,:/house/daniel:/bin/bash
Enter fullscreen mode

Exit fullscreen mode

Sure, you may modify the file contents utilizing any textual content editor like vim, nano or emacs however it’s thought-about to be a unhealthy thought until you realize what you might be doing.
You have to all the time use devoted instructions to change the file. To illustrate for an instance, you wish to add a brand new consumer to the system. For doing so, you could use adduser or useradd command as a substitute of manually enhancing the /and so on/passwd file utilizing a textual content editor.

/and so on/passwd file incorporates many strains, one for every consumer. The primary line incorporates details about root consumer adopted by system consumer accounts and regular consumer accounts.

It has 7 fields separated by colon(:).



1) Username :

That is the primary discipline in a line which represents the login title of the consumer. It has a size starting from 1 to 32 characters.



2) Password :

That is the second discipline in a line. In older linux methods, consumer’s encrypted password was saved right here. Now within the trendy methods, this discipline is changed by a personality x and the encrypted password is saved in a file known as /and so on/shadow.

If the sphere is clean, we do not want a password to login to the system.

To alter the password of any consumer, use passwd command which shops the password in encrypted kind in /and so on/shadow.



3) Person ID (UID):

That is the third discipline in a line. It incorporates a distinctive identifier of a consumer which is utilized by an working system to confer with a consumer.

UID 0 is reserved for root consumer.
UID 1-99 is reserved for different predefined accounts.
UID 100-999 is reserved for system accounts.
UID above 999 are for regular consumer accounts.



4) Group ID(GID):

That is the fourth discipline in a line. It determines the major group of the consumer. Customers can belong to multiple group in linux. To get a full checklist of teams a consumer belongs to, sort within the command:

teams <user_name>
Enter fullscreen mode

Exit fullscreen mode

The primary group within the output is the major group and the remainder are secondary teams.



5) GECOS :

That is the fifth discipline in a line. It incorporates comma-separated info concerning the consumer together with:

  • Full title
  • Room quantity
  • Work cellphone quantity and so on.



6) House listing :

That is the sixth discipline in a line which incorporates the path to the consumer’s house listing. By default, this path is beneath /house listing and is called after the consumer. For instance, for a consumer having a username daniel, his house listing can be /house/daniel.



7) Login Shell :

That is the seventh and the final discipline within the line. It incorporates path to the consumer’s default login shell. For many of the distributions, it’s bash having the trail /bin/bash.

It’s not essential to for it to be a shell. For instance, system directors can use nologin shell having path /sbin/nologin. So, if a consumer tries to login to an account with nologin shell, the nologin shell closes the connection.

That is it for the weblog. I hope you understood the format of the file /and so on/passwd.

Thanks for studying!

Add a Comment

Your email address will not be published. Required fields are marked *