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
video games:x:5:60:video games:/usr/video games:/usr/sbin/nologin
checklist:x:38:38:Mailing Listing Supervisor:/var/checklist:/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
tss:x:106:111:TPM software program stack,,,:/var/lib/tpm:/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 *