470 likes | 614 Views
Linux Based Networks University of Education. Instructor: Muhammad Amer Irshad. Today’s Agenda. User Administration. User Accounts. Because Linux is a multi-user system , the task of adding and maintaining user accounts is common in Linux system administration .
E N D
Linux Based NetworksUniversity of Education Instructor: Muhammad Amer Irshad
User Accounts Because Linux is a multi-user system, the task of adding and maintaininguser accounts is common in Linuxsystem administration. Upon a successful installation of a Linux distribution, two user accounts are configured: the root user and a normal user. These two user accounts represent the two basic types of users that are configurable with Linux.
The first type • The first type, the root user, is unique for several reasons. • It is the only user account with system wide privileges. • Other accounts can be set up as an exact clone of the root • user account, but it is strongly discouraged.
System Accounts • In your Linux distribution, you will see a number of accounts set up, like bin, daemon, adm, Ip, sync, shutdown, mail, operator, and others. • They are called "system accounts" and are used for varying • purposes, some self-explanatory, some not. • These accountsdo not have passwords because they are not • designed for login. • These special-purpose accounts are also called non-login • accounts. • They need to be in your password file. Do not delete them or some programs will not run.
Privileges of a root user • System administration tasks are performed from the root or superuser account. • The following list summarizes some of the duties and privileges of a system administrator: • Has complete access to all files and directories regardless of • owner and permissions • Controls user account administration • Performs system maintenance • Halts the system when necessary • Sets up initial user passwords • Changes passwords when necessary. • Installs software on the system
The Second Type A normal user account, is the type of account that is set up for each individual user. This type of account differs only in respect to access privileges and home directories.
Important It is good system practice to have a separate account for each individual user.Avoidaccounts that are shared, if possible.
Adding New Users • Required steps: • Edit the /etc/passwd file to define the user's account. • Set an initial password. • Create the user's home directory. • Extra steps (optional): • Copy default startup files to the user's home directory. • Add the user to the /etc/group file. • Set the user's mail home and establish mail aliases. • Enter the user in the site-wide user database (NIS). • Configure disk quotas. • Verify that the account is set up correctly. • Record accounting information.
User Accounts Utilities • Managing usersand groups has traditionally been tedious, • Red Hat Linux has a few tools and conventions that make users and groups easier to manage. • You can use useradd to create a new user from the shell • prompt • The easiest way to manage usersand groups is through $redhat-config-users
Account Setup Adding and deleting users is simple, but understanding the files involved with user account management is a bit more complex. The key to managing user accounts is to understand the underlying configuration files.
Key Configuration File The key file used in user account setup and configuration is the /etc/passwd file. This file is a simple ASCII text file.
/etc/passwd File Upon a successful installation, the contents of the /etc/passwd file resemble the following: • root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:daemon:x:2:2:daemon:/sbin:adm:x:3:4:adm:/var/adm:lp:x:4:7:lp:/var/spool/lpd:sync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:news:x:9:13:news:/var/spool/news:uucp:x:10:14:uucp:/var/spool/uucp:operator:x:11:0:operator:/root:games:x:12:100:games:/usr/games:gopher:x:13:30:gopher:/usr/lib/gopher-data:ftp:x:14:50:FTP User:/var/ftp:nobody:x:99:99:Nobody:/:xfs:x:43:43:X Font Server:/etc/X11/fs:/bin/falseapache:x:48:48:Apache:/var/www:/bin/falsenamed:x:25:25:Named:/var/named:/bin/falsegdm:x:42:42::/home/gdm:/bin/bashrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/bin/falserpc:x:32:32:Portmapper RPC user:/:/bin/falsepostgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bashmailnull:x:47:47::/var/spool/mqueue:/dev/nullmysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bashnscd:x:28:28:NSCD Daemon:/:/bin/falsepvm:x:24:24::/usr/share/pvm3:/bin/bashsquid:x:23:23::/var/spool/squid:/dev/null
Note • Each entry in /etc/passwd must be on one line. • Each field within each user's entry is separated from the next by a colon. The /etc/passwd file root:*:0:3:The Big Guy,143 MSB:/:/bin/sh daemon:*:1:5::/:/bin/sh farrell:*:100:15:Paul Farrell:/users/research/farrell/:/bin/csh stacke:*:101:15:Olaf P. Stackelberg:/users/fac/stack:/bin/csh pwang:*:102:15:Paul S. Wang:/users/research/wang:/usr/local/bin/tcsh abaqus57:x:53:13:License Manager:/var/log/abaqus57:/usr/bin/csh matlab:x:54:13:Matlab License Manager:/usr/local/matlab5:/usr/bin/csh catadm:x:55:13::/usr/local/abaqus:/bin/csh … /etc/passwd login_name:password:user_id:group_id:userinfo:home:shell
The /etc/passwd file contents • Login name • case sensitive and unique for users. • no more than 8 chars long, may include numbers, except in position 1. (for some old system only) • /etc/aliases can be used to set the alias of user name for most mail system like sendmail. • Pseudo-Logins execute the corresponding commands as their shells. Eg daemon, bin. • Encrypted password • Look like Xv8Q981g71oKKrequ, encrypted by MD5 or DES algorithms. • If null, no password is required, ie Press Enter directly! • change user's password with passwd. • /etc/passwd is world readable -> no security. (refer to the /etc/shadow section)
The /etc/passwd file contents • User ID • uid is the ID for the user, which must be unique. • UID 0 is reserved for root, and traditionally the lower number are kept for systems programs. • It is recommended that human users start at 500. • uid is a value between 0 and 65536. • It is a good idea to avoid reusing UIDs, since this avoids confusion when backups are restored. • Group ID • gid is the ID of the group that the user belongs to. • gid is generally a value between 0 an 65536. GID 0 is reserved for root and 1 is usually reserved for daemon. • Groups' info are defined in /etc/groups. • User Info (GECOS field) • No particular format, can be Full name, Address, Contact number, etc. • The finger command expects one to have comma delimited. • Can be modified by the chfn command.
The /etc/passwd file contents • Home directory • Users are placed in their home directory when they log in. Eg. /home/staff/zahid. • Home directories are usually named with the user's login name, and should be read, write and executable by the user. • If it is missing or invalid, a message such as "no home directory" will be printed or login disabled or login to the root directory. # mkdir /home/staff/zahid # chownzahid /home/staff/zahid # chgrpzahid /home/staff/zahid # chmod700 /home/staff/zahid • Shell • Specify a standard shell (sh, csh, bash, ksh, etc.), but can be a restricted shell, or a program. • Can be changed by chsh commands. • If the shell field is null, Bourne Shell is used.
Important Users • daemon: Owner of Unprivileged Software • Usually has uid1. • Controls the files that belong to UNIX system. • bin: Owner of System Commands • Owns directories that contain the system's command and most of the executable files. • sys (kmem): Owner of the Kernel and Memory Images • Owns special files such as /dev/kmem (kernel's address space), /dev/mem (the physical memory of system), and /dev/swap (image of the system's swap space). • nobody: Owner of Nothing • The owner of software that doesn't need or shouldn't have special permissions, eg fingerd.
The /etc/group file root:X:0:root daemon:X:1: bin:X:2:root,bin,daemon sys:X:3:root,bin,sys,adm adm:X:4:root,adm,daemon … /etc/group • Each line has, 4 colon separated fields, Group name password - never used GID - group ID number list of members • In practice, users are in the group given in the password file whether or not they are entered in that group in /etc/group.
/etc/shadow File The /etc/shadowpassword file looks similar to the following: root:$1$d5.gDvSX$nyQhvBgUGbw0GcNTxAdKR1:11507:0:99999:7::: • bin:*:11458:0:99999:7:::daemon:*:11458:0:99999:7:::adm:*:11458:0:99999:7:::lp:*:11458:0:99999:7:::sync:*:11458:0:99999:7:::shutdown:*:11458:0:99999:7:::halt:*:11458:0:99999:7:::mail:*:11458:0:99999:7:::
Secure Password Files • Modern UNIX systems like Linux and Solaris, place the passwords in a secure file (commonly called a shadow password file) or files elsewhere. • The format and location differs between systems, as does the entry in the password section of the normal password file. • The /etc/shadow file: • Its access permissions are much more restricted, only view by the root. • Provides also Password Aging, like password expiration.
root:$1$d5X$nyQBgUGbw0GcNTxAdKR1:11507:0:99999:7::: Much like the /etc/passwd file, the /etc/shadow file consists of single-line entries with colon-delimited fields. username:password:lastchg:min:max:warn:inactive:expire:flag username The user's login name (UID). password An encrypted password for the user, a lock string to indicate that the login is not accessible, or no string, which shows that there is no password for the login. lastchg The number of days between 1/1/70 and the date that the password was last modified. min The minimum number of days required between password changes. max The maximum number of days the password is valid. warn The number of days before password expires that the user is warned. inactive The number of days after password expires until the a/c is permanently disable. (-1 for disable the feature) expire A date, YYYY-MM-DD, specifying when the user will be disabled. (-1 for disable) flag Reserved for future use.
Adding Users User accounts can be added by directly editing the/etc/passwd file or by using a utility such as useradd, available in all Linux distributions. Default characteristics for each user account are defined by the settings in the/etc/login .defsfile, as follows
/etc/login.defs #QMAIL_DIR MaildirMAIL_DIR /var/spool/mail#MAIL_FILE .mail# Password aging controls:# PASS_MAX_DAYS Maximum number of days a password may be used.# PASS_MIN_DAYS Minimum number of days allowed between password changes.# PASS_MIN_LEN Minimum acceptable password length.# PASS_WARN_AGE Number of days warning given before a password expires.#PASS_MAX_DAYS 99999PASS_MIN_DAYS 0PASS_MIN_LEN 5PASS_WARN_AGE 7## Min/max values for automatic uid selection in useradd#UID_MIN 500UID_MAX 60000## Min/max values for automatic gid selection in groupadd#GID_MIN 500GID_MAX 60000## If defined, this command is run when removing a user.# It should remove any at/cron/print jobs etc. owned by# the user to be removed (passed as the first argument).##USERDEL_CMD /usr/sbin/userdel_local## If useradd should create home directories for users by default# On RH systems, we do. This option is ORed with the -m flag on# useradd command line.#CREATE_HOME yes
When we create a new home directory A new directory, /home/username, is created and populated with copies of the default files in the /etc/skel and /etc/skel.d directories (in that order).
To create a user from your command line you can run the useradd command. This will add a new entry in /etc/passwd and in /etc/shadow if you use shadow passwords using system defaults. ManagingUsers with Command Line Tools #useradd newuser Creatinga new user account
Creating a new user account • When I run the preceding command on my Red Hat system, • /etc/passwdshows a new line such as the following: • newuser:!!:506:506::/home/newuser:/bin/bash • If you remember the /etc/passwd fields from earlier discussion, You will see that the password field (the second field) is set to !!. • This means that this password is not set and the user cannot log in just yet. • So you will need to create a password for this user by running the passwd command as follows: #passwd newuser
Default Settings • The UIDand the GID values will be automatically selected by • useradd. • The home directory is created in the default top-levelhome • directory • The login shell is also selected from a system default. You will learn to set these defaults in a later section.
Overriding System Default If you would like to override a system default, you can specify a command line option To override the default home directory, use the -d new directory option #useradd newuser -d /www/newuser Note:useradd will create only the final directory and not the entire path.
Private Group The useradd that comes with Red Hal Linux creates a private group for the userwith the same name as the username.
Overriding System Default You can override the idea of private group by using the -g group option For example: This will make useradd create the new user (mjkabir) with the default group set to the users. #useradd mjkabir -g users
Assigning user an additional group You can use the -Gcomma-separated list of groups option. For example: Here the new user (mjkabir) will be added to the wheelandadmins groups in the /etc/group file. #useradd mjkabir -G wheel,admins
To Find Out which groups user belong to You can use the command to find out which user belongs to what group. #groups username
Creating a new group To create a new group, use the groupadd command. For example: #groupadd mygroup
To change or set a user's password, use the passwd command. For example: Note: When an ordinary user runs the passwd program, no username argument is required, because it will allow her to change only her own password. CHANGING A PASSWORD #passwd zahid
CHANGING THE SHELL If the default shell is not appropriate for a user, you may change it to any shell you list in /etc/shells. Use the chsh command to change a user's shell. For example: Note that a user can change her own shell using this command as well. You can also use the usermod command to modify the shell information as follows: #chsh zahid #usermod -s new shell path username
CHANGING THE HOME DIRECTORY To change the home directory of an existing user, run the usermod command as follows: For example, you can run the command as follows: However, if you would like to move the home directory contents to the new location, use the -m option as follows: #usermod -d new home directory username #usermod -d /home2/zahid zahid #usermod -d /home2/zahid -m zahid
CHANGING A DEFAULT GROUP To change the default group for a user, use the usermod command as follows: For example: This command will change the default group for user zahid to 512. #usermod -g group name or GID username #usermod -g 512 zahid
CHANGING ACCOUNT EXPIRATION DATE • If you are using shadow passwords, you can change the expiration date of a user account using the usermod command as follows: • For example: • This command will reset the account expiration date for user zahid to 12/31/2005. #usermod -e MM/DD/YY username • #usermod -e 12/31/2005 zahid
CHANGING FINGER INFORMATION You can also change the finger information, such as the full name and phone numbers. Run the chfn command to change a user's finger information. For example: #chfn zahid
Modifying an existing group • To modify an existing group name or GID, use the groupmod command. To rename a group to a new name, use the following syntax: • For example: • Here the existing novices group is renamed to experts. • #groupmod -n new group current group • #groupmod -n experts novices
Deleting a user account • To delete an existing user use the userdel command. For example: • This deletes a user called snake. • If you would like to remove the user's home directory and all the contents within the directory, use the -r option. • # userdel snake
Caution!! • userdel will not delete the user if the user is currently logged in.
Disabling a user account • If you would like to temporarily disable a user account, you can do one of the following: • Use the usermod -s new shell username' command to change the shell to /bin/false (make sure it is in your / etc/shells). This will disallow the user from logging into the system • If you are using the shadow passwords, you can use the • usermod -e MM/DD/YY username command to cause the user account to expire. • If you would like to disable all user account access for a • temporary reason, you can create a file called /etc/nologin with a message explaining why you arc not allowing access.