Flux rss

Linux - User management

First step for the administrator

When several people have access to a system, the administrator must manage the users. To do so, he must know the common commands and files to be configured.

The important files are:

  • the /etc/passwd file
  • the /etc/group file

The /etc/passwd file

The /etc/passwd file contains all the information relating to the user (login, passwords, etc.). Only the superuser (root) must be able to change it. It is therefore necessary to change the rights of this file so that it can only be read by other users.

This file has a special format making it possible to locate each user, each of its lines has the following format:

account_name : password : user_number : group_number : comment : directory : start_program
Seven fields are specified separated by the character ":":
  • the user's account name
  • the user's password(encrypted, of course)
  • the number identifying the user to the operating system (UID=User ID, user identification)
  • the number identifying the user's group (GID=Group ID, group identification)
  • the comment where information on the user or simply his real name can be found
  • the connection directory which is the directory in which the user finds himself after being connected to the system
  • the command is executed after connection to the system (often, this is the command interpreter)

Here is an example of a passwd file:

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/bin/bash
daemon:x:2:2:daemon:/sbin:/bin/bash
news:x:9:13:News system:/etc/news:/bin/bash
uucp:x:10:14::/var/lib/uucp/taylor_config:/bin/bash
cquoi:x:500:100:Cool......:/home/cquoi:/bin/bash

It is important to know that the passwords located in this file are encrypted. It is therefore useless to edit and replace the password field by directly typing the password, which would only cause the account to be blocked.

When a user connects, the login program compares the password typed in by the user (after encrypting it) with the password stored in the passwd file. If they do not match, the connection can not be established.

To prohibit use, simply replace the encrypted password by a star: "*".

Access to an account may potentially be left open by leaving the password field empty. Anybody wishing to connect with this account can then do so.
To be able to change an account password using the passwd command, you must either be a system administrator or the account owner (the system will then ask the user to enter the old password before asking him to enter the new password twice).

UID: (unique) identifier for each user account. Numbers beween 0 and 99 are frequently reserved for the machine's own accounts. Numbers higher than 100 are reserved for user accounts.

GID: group identifier. The default group (called group) has the number 50. This identifier is used in connection with access rights to the files. This issue will only concern you if your system has more than one user group. (In which case, you must pay attention to the /etc/group file.

From the shell, it is possible to change the command interpreter. To do so, use the chsh or passwd -s command. Linux will then look for the program you have specified in the /etc/shells file. Only commands that are present in this file will be accepted and will replace the current value of the start_program field. These restrictions do not apply to the superuser account.
Make sure that the access rights for the /etc/shells file are the same as for the /etc/passwd file
The superuser may not necessarily be called root. To change this, simply replace the root account name with the desired name.
A privileged account is an account whose identifier (UID, User ID) is zero.

The /etc/group file

The /etc/group file contains a list of users belonging to the different groups. In fact, when a large number of users have access to the system, they are frequently placed in different groups, each of which has it own access rights to the files and directories.

It has different fields that are separated by ":":

groupe_name : special_field : group_number : member1, member2

The special field is frequently blank.
The group number is the number which makes the link between the /etc/group and /etc/passwd files.

Here is an example of a /etc/group file:

root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:
tty:x:5:
disk:x:6:
lp:x:7:
wwwadmin:x:8:
kmem:x:9:
wheel:x:10:
mail:x:12:cyrus
news:x:13:news
  • When the ls command is used with the option -l, the group number is displayed with the number of the user to whom the file (or the directory) belongs. This unique number corresponds to a unique group name (often 8 characters max.).
  • The same user can appear in several groups. When he connects to the system he belongs to a group specified in the /etc/passwd (in the GID field). He can change this using the newgrp command. The file access rights are then defined.
  • File protections must prevent the modification of files by non-privileged users.
  • To add a group, the administrator can change the /etc/group file using a text editor. He can also use the addgroup or groupadd command (not always present). In the first instance, he will only have to add the line(s) relating to the groups. For example, the line:
    admin : : 56 : CCM
  • To add a user to a group, edit the /etc/group file and add the name at the end of the line, separating the names of the members using a comma.
  • To delete a group, edit the /etc/group file and delete the corresponding line. Please note, do not forget to change the the numbers (GID) of the deleted group in the /etc/passwd file, if users belonged to it. It is also important to search the files and directories of this group to change this (otherwise, the files and directories may become inaccessible).

Customizing the shell

Use the /etc/profile file to configure the shell. This relates to all users.

Firstly, find the Shell variables such as OPENWINHOME, PATH, etc.
Then, the type of terminal and the TERM variable are defined.
One part is reserved for the shell prompt, finally a last one makes it possible to define the colors for the ls command.

When Linux starts up, it is advisable to have the numeric keypad turned on, which does not happen by default.
There are then only several lines to be added to the /etc/profile file, which are:

INITTY=/dev/tty[1-7]
for tty in $INITTY;
do setleds -D +num < $tty
done


When connecting to the shell, the first thing that appears is the prompt, which can be configured how as user wants.
If the administrator wants a prompt which reads: "Hello#", just edit the /etc/profile file. This file contains a variable called PS1. All lines relating to this variable must then be preceded by a hash: #. So the line PS1='Hello#' must be added.

All that remains is to save and log on again. You will then notice several changes.
Tip: leave a blank space after the prompt to improve readability.

It is also possible to use variables in the prompt (for example, to display the time or name of the machine, etc.):

\d to add the date (English format)
\t to add the time(HH:MM:SS)
\u to add the user name
\r to return to the line
\w to add the full path of the current directory
\W to add the current directory
\h to add the name of the machine

The color can also be changed. To do so, use the variable PS1 as follows:

PS1='\[\033[num_colorm]desired_prompt\033[0m]'

The color number is shown in the list below:

Black 0;30
Red 0;31
Green 0;32
Brown 0;33
Blue 0;34
Violet 0;35
Cyan 0;36
Light Gray 0;37
Gray 1;30
Pink 1;31
Light Green 1;32
Light Brown 1;33
Light Blue 1;34
Light Violet 1;35
Light Cyan 1;36
White 1;37

Here is an example which shows the time followed by the user name in red:

PS1='\t \[\033[0;31m]\u\033[0m]'


Last update on Thursday October 16, 2008 02:43:15 PM.
This document entitled « Linux - User management » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the licence, as this note appears clearly.
Linux - The Vi editor Despite its very limited ergonomics, Vi i is one of the most popular text editors texte under Unix type systems (with Emacs and pico). Under Linux, there is a free version of Vi called Vim (Vi Improved). Vi (pronounced vee-eye) is an editor that is... en.kioskea.net/linux/linvi.php3
Linux - Mini HOW-TO Documents The mini HowTo documents are a set of documentations written by different people on very specific topics concerning Linux. Below you will find a (non exhaustive) list of HowTo documents written or translated into French: HOW-To Description 3Dfx-HOWTO... en.kioskea.net/linux/howto.php3
Linux - Compiling the kernel In this article, compiling the kernel under Linux is explained. The following explanations are based on version 2.4.20 of kernel, i.e. the most recent version of the kernel at the time this article was written (March 2003). The sources of the most... en.kioskea.net/linux/linkernel.php3
Log in remotely with SSH (Linux)Log in remotely with SSH (Linux) The commands below are relevant only if you have an existing account on the PC you want to connect and that a SSH server is installed. When using Linux the syntax is quite simple as the client part is... en.kioskea.net/faq/sujet-604-log-in-remotely-with-ssh-linux
Using SQLPlus under LinuxUsing SQLPlus under Linux You would be surprised to see that you can’t rollback your command with the up arrow (last command entered) or the backspace button (actual command correction).Special characters are displayed. Some existing... en.kioskea.net/faq/sujet-577-using-sqlplus-under-linux
Using an USB memory key under LinuxUsing an USB memory key under Linux Automatic setup based upon version used Mandriva Fedora Core Debian & consort Manual setup Automatic setup based upon version used Follow the procedure below to set up automatically your USB... en.kioskea.net/faq/sujet-702-using-an-usb-memory-key-under-linux
I wanna connect my xp client to linux serverHello, this is ravi chawla actually iam new learner with linux fundas and i now want to come up with telnet fundas so iam trying to connect my windows xp client with linux server via telnet but failed. so can you pls suggest me the process to this via... en.kioskea.net/forum/affich-18290-i-wanna-connect-my-xp-client-to-linux-server
Download Driver Ati Radeon Catalyst Linux x86To drive Ati Radeon Catalyst Linux x86 8.7 is a driver devoted to the cards Radeon HD of series following:X2900, 2600, on 2400, X1950, X1900, X1800, X1650, X1600, X1550, X1300, X1050, X850, X700, X600, X550, X300, 9800, 9700, X9600, X9550, X9500,... en.kioskea.net/telecharger/telecharger-850-driver-ati-radeon-catalyst-linux-x86
Download Avira AntiVir Personal free for Linux / FreeBSD / OpenBSD / SolarisFor Linux / FreeBSD / OpenBSD / Solaris Avira AntiVir PersonalEdition Classic is a very good and free antivirus which reliably protects your private computer against dangerous viruses, worms, Trojans, rootkits and costly dialers. en.kioskea.net/telecharger/telecharger-110-avira-antivir-personal-free-for-linux-freebsd-openbsd-solaris
Download Damn Small LinuxWhat does it happen of your ancient PC when you think it is obsolete? Here is the resolution which will enrapture the unhappy possessors of the old processors, "Damn Small".It is a distribution of Linux conceived to be light because she can work on... en.kioskea.net/telecharger/telecharger-304-damn-small-linux
Linux - Tree structure of files To ensury compatibility and portability, Linux systems comply with the sole FHS (File Hierarchy Standard) standard. The basic hierarchy is as follows: /the root, containing the main directories /bincontains essential executables of the system, used... en.kioskea.net/linux/linarb.php3
Linux - Tricks To mount a CD-ROM drive under Linux, log in as the system administrator, i.e. with the login "root". It is then sufficient to mount the drive, i.e. to "capture" the content of the CD-ROM drive in a directory (most of the time /mnt/cdrom/) by typing... en.kioskea.net/linux/linast.php3
Linux - Preparation of the system Linux does not require a state-of-the-art computer in minimal configuration: a 386SX processor or higher 4 MB of RAM (8 MB recommended) a hard disk controller and a hard disk with 20 MB of free space (100 MB recommended) (in practice, Linux can run... en.kioskea.net/linux/lininstpre.php3