Friday, September 11, 2009

Linux - users and group of users

There are three user types in Linux systems:
- root (as known as superuser) - has all access to all parts of Linux system
- system user - connected with some services inside of the system
- normal user.

Users' data is stored in /etc/passwd file. Each of rows in this file is connected with one user. Structure of each row is shown below.

login:password:UID:GID:name:homedir:shell

login - user's identifier
password - user's password (now it is usually stored in /etc/shadow file due to security improvement)
UID - User ID - root UID = 0, systems acount UID=100-999, user accounts UID>1000
GID - Group ID - number of main group of user
name - user's name (usually name and surname)
homedir - home dir of user
shell - default shell for user

For example this file can look like the following one:

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh


As it was mentioned before user passwords are stored in /etc/shadow file. Structure of rows from this file was shown below:

login:password:date1:num1:num2:num3:num4:date2:res

login - user's login
password - user's password (encoded)
User is able to insert some special characters in this place:
! or *- means that this account has been blocked
!! - user has not set any password yet
date - date of last password modification
num1 - number of days before the next password modification
num2 - number of days to change the password
num3 - number of days when the system informs user about password expiration
num4 - number of days after the account is blocked
date2 - date of block of account
res - reserved field

Example entry was shown below:

waldekd:$1$AZK6J/bg$BLkas/oh3BKHRas0b.3/f0:14479:0:99999:7:::

Every user in the Linux-based system belongs to one or more groups. Main group number connected with the user is included in the /etc/passwd file.
Groups' data is included in /etc/groups file.Each row from the file has structure as was shown below:

gr_name:pass:GID:users

gr_name - group name
pass - group password
GID - Group ID
users - users assigned to this group

Example file:
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:waldekd
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:


All passwords connected with group are stored in /etc/gshadow file. Its structure is similar to /etc/shadow file:

gr_name:pass:admins:users

gr_name - name of group
pass - group's password
admins - group's admins
users - users assigned to this group.

To get info about users and groups you can use command listed below:

id - prints info about UID, GID and other group user belongs to.
For example:

waldekd@waldekd-laptop:~$ id
uid=1000(waldekd) gid=1000(waldekd) groups=4(adm),20(dialout),24(cdrom),46(plugdev),108(lpadmin),123(admin),124(sambashare),1000(waldekd)

waldekd@waldekd-laptop:~$ id root
uid=0(root) gid=0(root) groups=0(root)


groups - lists group user belongs to.

waldekd@waldekd-laptop:~$ id root
uid=0(root) gid=0(root) groups=0(root)


finger - gets info about user.

waldekd@waldekd-laptop:~$ finger waldekd
Login: waldekd Name: Waldemar Dacko
Directory: /home/waldekd Shell: /bin/bash
On since Fri Sep 11 11:42 (CEST) on tty7 from :0
2 hours 34 minutes idle
On since Fri Sep 11 12:16 (CEST) on pts/0 from :0.0
No mail.
No Plan.


Adding user
To add some new user you can use on of these command:
useradd - creates some new user or modifies default settings of existing one.

waldekd@waldekd-laptop:~$ sudo useradd -d /home/magdalena -g users -s /bin/bash magdalena

If some of the settings are not provided by you the system defaults they according to the /etc/default/useradd file.
useradd -D modifies default settings.

adduser - adds user to the system

No comments:

Search This Blog