Linux User

Linux User

Each Linux user is identified to the system with a user name because that is a multi-user system

To this name the system associates a unique number (UID), a password, your full name, a boot directory (the home user) and a login shell (there are different shell programs, and choose between one or the other according to the characteristics of the user or the type of shell you prefer)

All these data saved the system in the /etc/passwd and /etc/shadow. The /etc/shadow file contains the encrypted password and data over the same (such as the validity time, in days to warn before expiry, every time you have to force your change, etc). The creation of this file came as a matter of safety, as the file passwd must be accessible to all users

Structure

The structure of the file passwd is the following:

user Not supported numbers at the beginning of a user name
x An “x” indicates that the password is stored in /etc/shadow, in the case of a “!” is that the user is locked. “!!” indicates that it has no password
uid Each user has an assigned id number (uid) between 0 (root) and 65535. Reserved for special users, such as root (which is always zero) and for users of services of the system. Systems-Red hat and derivatives between 1 and 499. In Debian systems and derivatives between 1 and 999
gid Each user is assigned a number id of the primary group (gid), that is to say, always belongs to at least one group, but can belong to more than one group
full name This option is designed for the user to enter their full name, although it can also be used to write a description of what makes that user or which is its usefulness, in the case of a service system
home directory Is the home folder that the user will use by default when you start your session
shell command The users associated with a system service, or users with limited permissions should not have a shell command, that is to say, ability to login in console mode, normally, this field is populated as /usr/bin/nologin or /bin/false

Some of the most common can be found in the following table:

User UID GID Home directory Terminal
root 0 0 /root /bin/bash
bin 1 1 /bin /sbin/nologin
daemon 2 2 /sbin /sbin/nologin
adm 3 4 /var/adm /sbin/nologin
lp 4 7 /var/spool/lpd /sbin/nologin
sync 5 0 /sbin /bin/sync
shutdown 6 0 /sbin /sbin/shutdown
halt 7 0 /sbin /sbin/halt
mail 8 12 /var/spool/mail /sbin/nologin
news 9 13 /var/spool/news
uucp 10 14 /var/spool/uucp /sbin/nologin
operator 11 0 /root /sbin/nologin
games 12 100 /usr/games /sbin/nologin
gopher 13 30 /usr/lib/gopher-data /sbin/nologin
ftp 14 50 /var/ftp /sbin/nologin
nobody 99 99 / /sbin/nologin
vcsa 69 69 /dev /sbin/nologin
rpm 37 37 /var/lib/rpm /bin/bash
wnn 49 49 /var/lib/wnn /bin/bash
ntp 38 38 /etc/ntp /sbin/nologin
nscd 28 28 / /bin/false
apache 48 48 /var/www /bin/false
mysql 27 27 /var/mysql /bin/bash
mailnull 47 47 /var/spool/mqueue /sbin/nologin
smmsp 51 51 /var/spool/mqueue /sbin/nologin
rpc 32 32 / /sbin/nologin
xfs 43 43 /etc/X11/fs /sbin/nologin
gdm 42 42 /var/gdm /sbin/nologin
rpcuser 29 29 /var/libs/nfs /sbin/nologin
nsfnobody 65534 65534 /var/libs/nfs /sbin/nologin
ident 98 98 / /sbin/nologin
radvd 75 75 / /sbin/nologin
sshd 74 74 /var/empty/sshd /sbin/login
postgres 26 26 /var/lib/pgsql /bin/bash
squid 23 23 /var/spool/quid /dev/null
named 25 25 /var/named /bin/false
pcap 77 77 /var/arpwatch /sbin/bash
amanda 33 6 /var/lib/amanda /bin/bash
mailman 41 41 /var/mailman /bin/false
netdump 34 34 /var/crash /bin/bash
ldap 55 55 /var/lib/ldap /bin/false
postfix 89 89 /var/spool/postfix /bin/true
privoxy 100 101 /etc/privoxy
Pvm 24 24 /usr/share/pvm3 /bin/bash

Add

The command to add a user is useradd

In the example we created the patxi user who belongs to the users group and ftp, has as shell /bin/shell, we assign the password key and their home folder will be /home/patxi

This command supports the following parameters:

-d User's home directory
-s The user's Shell
-p Password
-g Primary group to which we assign the user
-G Groups which the user belongs
-m We force the creation of the directory in your home

In the file /etc/default/useradd saved default settings for the useradd command and in the directory /etc/skel are the files and directories by default will be in the user's home directory when you create it

Edit

The command to modify users is usermod

In the example we have modified the user patxi who belonged to the group users and ftp, now his main group is a server, although it still belongs to the groups users and ftp

This command supports the following parameters:

-d To modify a user's home directory
-s Modify the user's shell
-p Modify Password
-g Change primary group to which we assign the user
-G Modify groups which the user belongs

Delete

The command to delete users is userdel

In the example deletion by user patxi and in addition we have forced to delete the contents of your home when you use the-r parameter, if we had not used, would still exist

Change the key

The command to change the key of a user is the passwd command. Keep in mind that you must have sufficient permissions to be able to make the change, either because of who is running the command is the user or the superuser root

If we want to change the password of the root user, and we have sufficient permissions, can be done by leaving the parameter empty user

shadow

The structure of the file shadow is the following:

user Name of the user
encrypted password The password with a strong encryption
1 Days since 1-1-1970 where the password was changed for the last time
2 The minimum number of days between password changes
3 Maximum days of validity of the account
4 Days of warning before password expires
5 Days after a password expires to disable account
6 Expiration date. days since 1-1-1970, where the account is deshabilatada and the user will not be able to log in

Groups Linux

The users are grouped into groups. The groups are also identified by a name and the system associates an identification number (GID). Every user has a primary group, but can belong to multiple groups, which inherits its privileges. Groups allow you to give the rights and restrict options globally to multiple users

The relationship of the groups is saved in the file /etc/group. There is also the file /etc/gshadow for encrypted passwords of group, although it is not very used

Structure

The structure of the group file is the following:

group The name of the group (it is recommended that you do not have more than 8 characters)
x An “x” indicates that the password is stored in /etc/gshadow
gid Each group is assigned a number identifier (gid) between 0 (root) and 65535 (the gid 0 to 499 are reserved by the system), so it will start numbering from 500
members list List of the members of the group, separated by commas (without spaces)

Some of the most common groups can be found in the following table:

Group GID Members
root 0 root
bin 1 root, bin, daemon
daemon 2 root, bin, daemon
sys 3 root, bin, adm
adm 4 root, adm, daemon
tty 5
disk 6 root
lp 7
mem 8
kmem 9
wheel 10 root
mail 12 mail
news 13 news
uucp 14 uucp
man 15
games 20
gopher 30
dip 40
ftp 50
lock 54
nobody 99
users 100
slocate 21
floppy 19
vcsa 69
rpm 37 rpm
utmp 22
wnn 49
ntp 38
nscd 28
apache 48
mysql 27
mailnull 47
smmsp 51
rpc 32
xfs 43
gdm 42
rpcuser 29
nfsnobody 65534
ident 98
radvd 75
sshd 74
postgres 26
squid 23
named 25
pcap 77
wine 66
Mailman 41
netdump 34
ldap 55
postdrop 90
postfix 89
privoxy 101
pvm 24

Add

The command to add groups groupadd

In the example we have set the group server with a gid of 500, in case you do not put anything you would use the greater than 500 is not used by another group. You can use the-g parameter to set the gid manually

If you want to add existing users to the newly created group will use the gpasswd command

In the example we added the user patxi with the parameter -a to the group server

Edit

The command to change groups is groupmod

In the example we have modified the gid to 501 of the group server

This command supports the following parameters:

-g Change gid of the group
-n Modify the name of the group

This command only makes changes in the file /etc/group, so the rest of
modifications involved in changing the gid of a group, you have to do manually in the files /etc/passwd and /etc/gshadow

Delete

The command to delete a group groupdel

In the example deleted the group server

You cannot delete a group that is a initial group for any user, without first deleting the user

The command does not traverse the file system looking for files owned by the group. If
we want to remove them, we have manually or with command-deletion of files

If we want to delete existing users to the newly created group will use the gpasswd command

In the example we have removed the user patxi with the-d parameter of the group server. But this will not delete the home directory of the group