The control of users and groups is a core element of Fedora system administration. This chapter explains how to add, manage, and delete users and groups in the graphical user interface and on the command line, and covers advanced topics, such as creating group directories.

1. Introduction to Users and Groups

  While users can be either people (meaning accounts tied to physical users) or accounts which exist for specific applications to use, groups are logical expressions of organization, tying users together for a common purpose. Users within a group share the same permissions to read, write, or execute files owned by that group.

  Each user is associated with a unique numerical identification number called a user ID (UID). Likewise, each group is associated with a group ID (GID). A user who creates a file is also the owner and group owner of that file. The file is assigned separate read, write, and execute permissions for the owner, the group, and everyone else. The file owner can be changed only by root, and access permissions can be changed by both the root user and file owner.

  Additionally, Fedora supports access control lists (ACLs) for files and directories which allow permissions for specific users outside of the owner to be set. For more information about this feature, see the Access Control Lists chapter of the Storage Administration Guide.

1.1. User Private Groups

  Fedora uses a user private group (UPG) scheme, which makes UNIX groups easier to manage. A user private group is created whenever a new user is added to the system. It has the same name as the user for which it was created and that user is the only member of the user private group.

  User private groups make it safe to set default permissions for a newly created file or directory, allowing both the user and the group of that user to make modifications to the file or directory.

  The setting which determines what permissions are applied to a newly created file or directory is called a umask and is configured in the /etc/bashrc file. Traditionally on UNIX-based systems, the umask is set to 022, which allows only the user who created the file or directory to make modifications. Under this scheme, all other users, including members of the creator's group, are not allowed to make any modifications. However, under the UPG scheme, this “group protection” is not necessary since every user has their own private group.

  A list of all groups is stored in the /etc/group configuration file.

1.2. Shadow Passwords

  In environments with multiple users, it is very important to use shadow passwords provided by the shadow-utils package to enhance the security of system authentication files. For this reason, the installation program enables shadow passwords by default.

  The following is a list of the advantages shadow passwords have over the traditional way of storing passwords on UNIX-based systems:

  • Shadow passwords improve system security by moving encrypted password hashes from the world-readable /etc/passwd file to /etc/shadow, which is readable only by the root user.
  • Shadow passwords store information about password aging.
  • Shadow passwords allow the /etc/login.defs file to enforce security policies.

  Most utilities provided by the shadow-utils package work properly whether or not shadow passwords are enabled. However, since password aging information is stored exclusively in the /etc/shadow file, some utilities and commands do not work without first enabling shadow passwords:

  • The chage utility for setting password-aging parameters. For details, see the Password Security section in the Fedora 22 Security Guide.
  • The gpasswd utility for administrating the /etc/group file.
  • The usermod command with the -e, --expiredate or -f, --inactive option.
  • The useradd command with the -e, --expiredate or -f, --inactive option.

2. Managing Users in a Graphical Environment

  The Users utility allows you to view, modify, add, and delete local users in the graphical user interface.

2.1. Using the Users Settings Tool

  Press the Super key to enter the Activities Overview, type Users and then press Enter. The Users settings tool appears. The Super key appears in a variety of guises, depending on the keyboard and other hardware, but often as either the Windows or Command key, and typically to the left of the Spacebar.

  To make changes to the user accounts, first select the Unlock button and authenticate yourself as indicated by the dialog box that appears. Note that unless you have superuser privileges, the application will prompt you to authenticate as root. To add and remove users, select the + and - button respectively. To add a user to the administrative group wheel, change the Account Type from Standard to Administrator. To edit a user's language setting, select the language and a drop-down menu appears.

  When a new user is created, the account is disabled until a password is set. The Add User menu contains the options to set a password by the administrator immediately, or to allow the user to choose a password at the first login.

3. Using Command Line Tools

  Apart from the Users settings tool described in Section 2, “Managing Users in a Graphical Environment”, which is designed for basic managing of users, you can use command line tools for managing users and groups that are listed in Table 1, “Command line utilities for managing users and groups”.

  Table 1. Command line utilities for managing users and groups

Utilities Description
id Displays user and group IDs.
useradd, usermod, userdel Standard utilities for adding, modifying, and deleting user accounts.
groupadd, groupmod, groupdel Standard utilities for adding, modifying, and deleting groups.
gpasswd Standard utility for administering the /etc/group configuration file.
pwck, grpck Utilities that can be used for verification of the password, group, and associated shadow files.
pwconv, pwunconv Utilities that can be used for the conversion of passwords to shadow passwords, or back from shadow passwords to standard passwords.
grpconv, grpunconv Similar to the previous, these utilities can be used for conversion of shadowed information for group accounts.

3.1. Adding a New User

  To add a new user to the system, type the following at a shell prompt as root:

useradd [options] username

  …where options are command-line options as described in Table 2, “Common useradd command-line options”.

  By default, the useradd command creates a locked user account. To unlock the account, run the following command as root to assign a password:

passwd username

  Optionally, you can set a password aging policy. See Section 3.3, “Enabling Password Aging” for information on how to enable password aging.

  Table 2. Common useradd command-line options

Option Description
-c 'comment' comment can be replaced with any string. This option is generally used to specify the full name of a user.
-d home_directory Home directory to be used instead of default /home/username/.
-e date Date for the account to be disabled in the format YYYY-MM-DD.
-f days Number of days after the password expires until the account is disabled. If 0 is specified, the account is disabled immediately after the password expires. If -1 is specified, the account is not disabled after the password expires.
-g group_name Group name or group number for the user's default (primary) group. The group must exist prior to being specified here.
-G group_list List of additional (supplementary, other than default) group names or group numbers, separated by commas, of which the user is a member. The groups must exist prior to being specified here.
-m Create the home directory if it does not exist.
-M Do not create the home directory.
-N Do not create a user private group for the user.
-p password The password encrypted with crypt.
-r Create a system account with a UID less than 1000 and without a home directory.
-s User's login shell, which defaults to /bin/bash.
-u uid User ID for the user, which must be unique and greater than 999.

  The command-line options associated with the usermod command are essentially the same. Note that if you want to add a user to another supplementary group, you need to use the -a, --append option with the -G option. Otherwise the list of supplementary groups for the user will be overwritten by those specified with the usermod -G command.

  The following steps illustrate what happens if the command useradd juan is issued on a system that has shadow passwords enabled:

1.A new line for juan is created in /etc/passwd:

juan:x:1001:1001::/home/juan:/bin/bash

  The line has the following characteristics:

  • It begins with the user name juan.
  • There is an x for the password field indicating that the system is using shadow passwords.
  • A UID greater than 999 is created. Under Fedora, UIDs below 1000 are reserved for system use and should not be assigned to users.
  • A GID greater than 999 is created. Under Fedora, GIDs below 1000 are reserved for system use and should not be assigned to users.
  • The optional GECOS information is left blank. The GECOS field can be used to provide additional information about the user, such as their full name or phone number.
  • The home directory for juan is set to /home/juan/.
  • The default shell is set to /bin/bash.

2.A new line for juan is created in /etc/shadow:

juan:!!:14798:0:99999:7:::

  The line has the following characteristics:

  • It begins with the username juan.
  • Two exclamation marks (!!) appear in the password field of the /etc/shadow file, which locks the account.
  • If an encrypted password is passed using the -p flag, it is placed in the /etc/shadow file on the new line for the user.
  • The password is set to never expire.

3.A new line for a group named juan is created in /etc/group:

juan:x:1001:

  A group with the same name as a user is called a user private group. For more information on user private groups, see Section 1.1, “User Private Groups”.

  The line created in /etc/group has the following characteristics:

  • It begins with the group name juan.
  • An x appears in the password field indicating that the system is using shadow group passwords.
  • The GID matches the one listed for juan's primary group in /etc/passwd.

4.A new line for a group named juan is created in /etc/gshadow:

juan:!::

  The line has the following characteristics:

  • It begins with the group name juan.
  • An exclamation mark (!) appears in the password field of the /etc/gshadow file, which locks the group.
  • All other fields are blank.

5.A directory for user juan is created in the /home/ directory:

~]# ls -ld /home/juan
drwx------. 4 juan juan 4096 Mar  3 18:23 /home/juan

  This directory is owned by user juan and group juan. It has read, write, and execute privileges only for the user juan. All other permissions are denied.

6.The files within the /etc/skel/ directory (which contain default user settings) are copied into the new /home/juan/ directory. The contents of /etc/skel/ may vary depending on installed applications:

~]# ls -la /home/juan
total 24
drwx------. 4 juan juan 4096 Mar  3 18:23 .
drwxr-xr-x. 5 root root 4096 Mar  3 18:23 ..
-rw-r--r--. 1 juan juan   18 Jul 09 08:43 .bash_logout
-rw-r--r--. 1 juan juan  176 Jul 09 08:43 .bash_profile
-rw-r--r--. 1 juan juan  124 Jul 09 08:43 .bashrc
drwxr-xr-x. 4 juan juan 4096 Jul 09 08:43 .mozilla

  At this point, a locked account called juan exists on the system. To activate it, the administrator must next assign a password to the account using the passwd command and, optionally, set password aging guidelines.

3.2. Adding a New Group

  To add a new group to the system, type the following at a shell prompt as root:

groupadd [options] group_name

  …where options are command-line options as described in Table 3, “Common groupadd command-line options”.

  Table 3. Common groupadd command-line options

Option Description
-f, --force When used with -g gid and gid already exists, groupadd will choose another unique gid for the group.
-g gid Group ID for the group, which must be unique and greater than 999.
-K, --key key=value Override /etc/login.defs defaults.
-o, --non-unique Allows creating groups with duplicate GID.
-p, --password password Use this encrypted password for the new group.
-r Create a system group with a GID less than 1000.

3.3. Enabling Password Aging

  For security reasons, it is advisable to require users to change their passwords periodically. This can be done by using the chage command.

  Shadow passwords must be enabled to use the chage command. For more information, see Section 1.2, “Shadow Passwords”.

  To configure password expiration for a user from a shell prompt, run the following command as root:

chage [options] username

  …where options are command line options as described in Table 4, “chage command line options”. When the chage command is followed directly by a username (that is, when no command line options are specified), it displays the current password aging values and allows you to change them interactively.

  Table 4. chage command line options

Option Description
-d days Specifies the number of days since January 1, 1970 the password was changed.
-E date Specifies the date on which the account is locked, in the format YYYY-MM-DD. Instead of the date, the number of days since January 1, 1970 can also be used.
-I days Specifies the number of inactive days after the password expiration before locking the account. If the value is 0, the account is not locked after the password expires.
-l Lists current account aging settings.
-m days Specify the minimum number of days after which the user must change passwords. If the value is 0, the password does not expire.
-M days Specify the maximum number of days for which the password is valid. When the number of days specified by this option plus the number of days specified with the -d option is less than the current day, the user must change passwords before using the account.
-W days Specifies the number of days before the password expiration date to warn the user.

  You can configure a password to expire the first time a user logs in. This forces users to change passwords immediately.

1.Set up an initial password. There are two common approaches to this step: you can either assign a default password, or you can use a null password.

  To assign a default password, type the following at a shell prompt as root:

passwd username

  To assign a null password instead, use the following command:

passwd -d username

2.Force immediate password expiration by running the following command as root:

chage -d 0 username

  This command sets the value for the date the password was last changed to the epoch (January 1, 1970). This value forces immediate password expiration no matter what password aging policy, if any, is in place.

  Upon the initial log in, the user is now prompted for a new password.

3.4. Enabling Automatic Logouts

  Especially when the user is logged in as root, an unattended login session may pose a significant security risk. To reduce this risk, you can configure the system to automatically log out idle users after a fixed period of time:

1.Make sure the screen package is installed. You can do so by running the following command as root:

dnf install screen

  For more information on how to install packages in Fedora, refer to 在Fedora 22中使用DNF进行软件包管理.

2.As root, add the following line at the beginning of the /etc/profile file to make sure the processing of this file cannot be interrupted:

trap "" 1 2 3 15

3.Add the following lines at the end of the /etc/profile file to start a screen session each time a user logs in to a virtual console or remotely:

SCREENEXEC="screen"
if [ -w $(tty) ]; then
  trap "exec $SCREENEXEC" 1 2 3 15
  echo -n 'Starting session in 10 seconds'
  sleep 10
  exec $SCREENEXEC
fi

  Note that each time a new session starts, a message will be displayed and the user will have to wait ten seconds. To adjust the time to wait before starting a session, change the value after the sleep command.

4.Add the following lines to the /etc/screenrc configuration file to close the screen session after a given period of inactivity:

idle 120 quit
autodetach off

  This will set the time limit to 120 seconds. To adjust this limit, change the value after the idle directive.

  Alternatively, you can configure the system to only lock the session by using the following lines instead:

idle 120 lockscreen
autodetach off

  This way, a password will be required to unlock the session.

  The changes take effect the next time a user logs in to the system.

3.5. Creating Group Directories

  System administrators usually like to create a group for each major project and assign people to the group when they need to access that project's files. With this traditional scheme, file management is difficult; when someone creates a file, it is associated with the primary group to which they belong. When a single person works on multiple projects, it becomes difficult to associate the right files with the right group. However, with the UPG scheme, groups are automatically assigned to files created within a directory with the setgid bit set. The setgid bit makes managing group projects that share a common directory very simple because any files a user creates within the directory are owned by the group that owns the directory.

  For example, a group of people need to work on files in the /opt/myproject/ directory. Some people are trusted to modify the contents of this directory, but not everyone.

1.As root, create the /opt/myproject/ directory by typing the following at a shell prompt:

mkdir /opt/myproject

2.Add the myproject group to the system:

groupadd myproject

3.Associate the contents of the /opt/myproject/ directory with the myproject group:

chown root:myproject /opt/myproject

4.Allow users in the group to create files within the directory and set the setgid bit:

chmod 2775 /opt/myproject

  At this point, all members of the myproject group can create and edit files in the /opt/myproject/ directory without the administrator having to change file permissions every time users write new files. To verify that the permissions have been set correctly, run the following command:

~]# ls -ld /opt/myproject
drwxrwsr-x. 3 root myproject 4096 Mar  3 18:31 /opt/myproject

5.Add users to the myproject group:

usermod -aG myproject username

4. Additional Resources

  For information about various utilities for managing users and groups, see the following manual pages:

  • useradd(8) — The manual page for the useradd command documents how to use it to create new users.
  • userdel(8) — The manual page for the userdel command documents how to use it to delete users.
  • usermod(8) — The manual page for the usermod command documents how to use it to modify users.
  • groupadd(8) — The manual page for the groupadd command documents how to use it to create new groups.
  • groupdel(8) — The manual page for the groupdel command documents how to use it to delete groups.
  • groupmod(8) — The manual page for the groupmod command documents how to use it to modify group membership.
  • gpasswd(1) — The manual page for the gpasswd command documents how to manage the /etc/group file.
  • grpck(8) — The manual page for the grpck command documents how to use it to verify the integrity of the /etc/group file.
  • pwck(8) — The manual page for the pwck command documents how to use it to verify the integrity of the /etc/passwd and /etc/shadow files.
  • pwconv(8) — The manual page for the pwconv, pwunconv, grpconv, and grpunconv commands documents how to convert shadowed information for passwords and groups.
  • id(1) — The manual page for the id command documents how to display user and group IDs.

  For information about related configuration files, see:

  • group(5) — The manual page for the /etc/group file documents how to use this file to define system groups.
  • passwd(5) — The manual page for the /etc/passwd file documents how to use this file to define user information.
  • shadow(5) — The manual page for the /etc/shadow file documents how to use this file to set passwords and account expiration information for the system.

Fedora 22中的用户和用户组管理的更多相关文章

  1. Fedora 22中的RPM软件包管理工具

    Introduction The RPM Package Manager (RPM) is an open packaging system that runs on Fedora as well a ...

  2. Linux用户和权限——用户和用户组管理

    Linux用户和权限——用户和用户组管理 摘要:本文主要介绍了Linux系统中的用户和用户组管理. 用户和用户组 含义 在使用Linux系统时,虽然输入的是自己的用户名和密码,但其实Linux并不认识 ...

  3. Linux 用户和用户组管理

    Linux 用户和用户组管理 Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统. 用户的账号一方面可以帮助 ...

  4. Linux用户和用户组管理总结

    Linux下和用户和用户组管理有关的配置文件: /etc/group Group account information. /etc/gshadow Secure group account info ...

  5. Linux系列教程(十五)——Linux用户和用户组管理之用户管理命令

    上篇博客我们介绍了用户管理的相关配置文件,包括用户信息文件/etc/passwd,用户密码文件/etc/shadow:然后介绍了用户组信息文件/etc/group,用户组密码文件/etc/gshado ...

  6. Linux基础学习(7)--用户和用户组管理

    第七章——用户和用户组管理 一.用户配置文件 1.用户信息文件/etc/passwd: (1)用户管理简介:所以越是对服务器安全性要求高的服务器,越需要建立合理的用户权限等级制度和服务器操作规范.   ...

  7. Linux命令——用户和用户组管理

    Linux命令--用户和用户组管理 命令groupadd 作用:新增组 格式:groupadd [-g GID] groupname 参数:-g,指定GID,一般从500开始 说明:一般不必加-g参数 ...

  8. [Linux/Unix]用户和用户组管理

    Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统的用户,都必须拥有自己的账号. 实现用户的管理,主要做: 用户账号的添加.删除.修改: 用户口令的管理: 用户组的管理. (一)用户的 ...

  9. 八、Linux 用户和用户组管理

    Linux 用户和用户组管理 Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统. 用户的账号一方面可以帮助 ...

随机推荐

  1. MVVM模式和在WPF中的实现(二)数据绑定

    MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  2. 谈谈如何使用Netty开发实现高性能的RPC服务器

    RPC(Remote Procedure Call Protocol)远程过程调用协议,它是一种通过网络,从远程计算机程序上请求服务,而不必了解底层网络技术的协议.说的再直白一点,就是客户端在不必知道 ...

  3. dll文件32位64位检测工具以及Windows文件夹SysWow64的坑

    自从操作系统升级到64位以后,就要不断的需要面对32位.64位的问题.相信有很多人并不是很清楚32位程序与64位程序的区别,以及Program Files (x86),Program Files的区别 ...

  4. Mysql事务探索及其在Django中的实践(一)

    前言 很早就有想开始写博客的想法,一方面是对自己近期所学知识的一些总结.沉淀,方便以后对过去的知识进行梳理.追溯,一方面也希望能通过博客来认识更多相同技术圈的朋友.所幸近期通过了博客园的申请,那么今天 ...

  5. ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(持续更新中...)

    开发工具:VS2015(2012以上)+SQL2008R2以上数据库  您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB  升级后界面效果如下: 任务调度系统界面 http: ...

  6. nginx+iis+redis+Task.MainForm构建分布式架构 之 (redis存储分布式共享的session及共享session运作流程)

    本次要分享的是利用windows+nginx+iis+redis+Task.MainForm组建分布式架构,上一篇分享文章制作是在windows上使用的nginx,一般正式发布的时候是在linux来配 ...

  7. iOS开发之ReactiveCocoa下的MVVM(干货分享)

    最近工作比较忙,但还是出来更新博客了,今天给大家分享一些ReactiveCocoa以及MVVM的一些东西,干活还是比较足的.在之前发表过一篇博文,名字叫做<iOS开发之浅谈MVVM的架构设计与团 ...

  8. RabbitMq应用一

    RabbitMq应用一 RabbitMQ的具体概念,百度百科一下,我这里说一下我的理解,如果有少或者不对的地方,欢迎纠正和补充. 一个项目架构,小的时候,一般都是传统的单一网站系统,或者项目,三层架构 ...

  9. JS继承类相关试题

    题目一: //有关于原型继承的代码如下:function Person(name) {   this.name = name;}Person.prototype = {     getName : f ...

  10. 通过AngularJS实现前端与后台的数据对接(一)——预备工作篇

    最近,笔者在做一个项目:使用AngularJS,从而实现前端与后台的数据对接.笔者这是第一次做前端与后台的数据对接的工作,因此遇到了许多问题.笔者在这些问题中,总结了一些如何实现前端与后台的数据对接的 ...