欢迎光临
我们一直在努力

Linux 用户和用户组管理65658

Linux 用户和用户组管理

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

用户的账号一方面可以帮助系统管理员对使用系统的用户进行跟踪,并控制他们对系统资源的访问;另一方面也可以帮助用户组织文件,并为用户提供安全性保护。

每个用户账号都拥有一个唯一的用户名和各自的口令。

用户在登录时键入正确的用户名和口令后,就能够进入系统和自己的主目录。

实现用户账号的管理,要完成的工作主要有如下几个方面:

  • 用户账号的添加、删除与修改。
  • 用户口令的管理。
  • 用户组的管理。

一、Linux系统用户账号的管理

用户账号的管理工作主要涉及到用户账号的添加、修改和删除。

添加用户账号就是在系统中创建一个新账号,然后为新账号分配用户号、用户组、主目录和登录Shell等资源。刚添加的账号是被锁定的,无法使用。

1、添加新的用户账号使用useradd命令,其语法如下:

useradd 选项 用户名

参数说明:

  • 选项:

    • -c comment 指定一段注释性描述。
    • -d 目录 指定用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录。
    • -g 用户组 指定用户所属的用户组。
    • -G 用户组,用户组 指定用户所属的附加组。
    • -s Shell文件 指定用户的登录Shell。
    • -u 用户号 指定用户的用户号,如果同时有-o选项,则可以重复使用其他用户的标识号。
  • 用户名:

    指定新账号的登录名。

实例1

# useradd –d /home/sam -m sam

此命令创建了一个用户sam,其中-d和-m选项用来为登录名sam产生一个主目录 /home/sam(/home为默认的用户主目录所在的父目录)。

实例2

# useradd -s /bin/sh -g group –G adm,root gem

此命令新建了一个用户gem,该用户的登录Shell是 /bin/sh,它属于group用户组,同时又属于adm和root用户组,其中group用户组是其主组。

这里可能新建组:#groupadd group及groupadd adm

增加用户账号就是在/etc/passwd文件中为新用户增加一条记录,同时更新其他系统文件如/etc/shadow, /etc/group等。

Linux提供了集成的系统管理工具userconf,它可以用来对用户账号进行统一管理。

2、删除帐号

如果一个用户的账号不再使用,可以从系统中删除。删除用户账号就是要将/etc/passwd等系统文件中的该用户记录删除,必要时还删除用户的主目录。

删除一个已有的用户账号使用userdel命令,其格式如下:

userdel 选项 用户名

常用的选项是 -r,它的作用是把用户的主目录一起删除。

例如:

# userdel -r sam

此命令删除用户sam在系统文件中(主要是/etc/passwd, /etc/shadow, /etc/group等)的记录,同时删除用户的主目录。

3、修改帐号

修改用户账号就是根据实际情况更改用户的有关属性,如用户号、主目录、用户组、登录Shell等。

修改已有用户的信息使用usermod命令,其格式如下:

usermod 选项 用户名

常用的https://avg.163.com/topic/detail/10130188 https://avg.163.com/topic/detail/10130163 https://avg.163.com/topic/detail/10130162 https://avg.163.com/topic/detail/10130157 https://avg.163.com/topic/detail/10130145 https://avg.163.com/topic/detail/10130135 https://avg.163.com/topic/detail/10130114 https://avg.163.com/topic/detail/10130108 https://avg.163.com/topic/detail/10130105 https://avg.163.com/topic/detail/10130077 https://avg.163.com/topic/detail/10130036 https://avg.163.com/topic/detail/10130029 https://avg.163.com/topic/detail/10130023 https://avg.163.com/topic/detail/10130013 https://avg.163.com/topic/detail/10130007 https://avg.163.com/topic/detail/10129982 https://avg.163.com/topic/detail/10129980 https://avg.163.com/topic/detail/10129847 https://avg.163.com/topic/detail/10129915 https://avg.163.com/topic/detail/10127969 https://avg.163.com/topic/detail/10129908 https://avg.163.com/topic/detail/10129890 https://avg.163.com/topic/detail/10129877 https://avg.163.com/topic/detail/10129862 https://avg.163.com/topic/detail/10129853 https://avg.163.com/topic/detail/10129828 https://avg.163.com/topic/detail/10129809 https://avg.163.com/topic/detail/10129788 https://avg.163.com/topic/detail/10129767 https://avg.163.com/topic/detail/10129760 https://avg.163.com/topic/detail/10129734 https://avg.163.com/topic/detail/10129724 https://avg.163.com/topic/detail/10129723 https://avg.163.com/topic/detail/10129714 https://avg.163.com/topic/detail/10129719 https://avg.163.com/topic/detail/10129694 https://avg.163.com/topic/detail/10129670 https://avg.163.com/topic/detail/10129652 https://avg.163.com/topic/detail/10128677 https://avg.163.com/topic/detail/10129609 https://avg.163.com/topic/detail/10129606 https://avg.163.com/topic/detail/10129595 https://avg.163.com/topic/detail/10128111 https://avg.163.com/topic/detail/10129582 https://avg.163.com/topic/detail/10129547 https://avg.163.com/topic/detail/10129564 https://avg.163.com/topic/detail/10129540 https://avg.163.com/topic/detail/10129503 https://avg.163.com/topic/detail/10129488 https://avg.163.com/topic/detail/10129450 https://avg.163.com/topic/detail/10129402 https://avg.163.com/topic/detail/10129398 https://avg.163.com/topic/detail/10129388 https://avg.163.com/topic/detail/10129386 https://avg.163.com/topic/detail/10129337 https://avg.163.com/topic/detail/10129322 https://avg.163.com/topic/detail/10127962 https://avg.163.com/topic/detail/10129251 https://avg.163.com/topic/detail/10129230 https://avg.163.com/topic/detail/10129229 https://avg.163.com/topic/detail/10129207 https://avg.163.com/topic/detail/10129192 https://avg.163.com/topic/detail/10129162 https://avg.163.com/topic/detail/10129156 https://avg.163.com/topic/detail/10129140 https://avg.163.com/topic/detail/10129127 https://avg.163.com/topic/detail/10129130 https://avg.163.com/topic/detail/10129083 https://avg.163.com/topic/detail/10129067 https://avg.163.com/topic/detail/10129063 https://avg.163.com/topic/detail/10129048 https://avg.163.com/topic/detail/10129033 https://avg.163.com/topic/detail/10129006 https://avg.163.com/topic/detail/10128988 https://avg.163.com/topic/detail/10128991 https://avg.163.com/topic/detail/10128962 https://avg.163.com/topic/detail/10128922 https://avg.163.com/topic/detail/10128907 https://avg.163.com/topic/detail/10126834 https://avg.163.com/topic/detail/10128861 https://avg.163.com/topic/detail/10128854 https://avg.163.com/topic/detail/10128818 https://avg.163.com/topic/detail/10128806 https://avg.163.com/topic/detail/10128796 https://avg.163.com/topic/detail/10128787 https://avg.163.com/topic/detail/10128771 https://avg.163.com/topic/detail/10128556 https://avg.163.com/topic/detail/10128741 https://avg.163.com/topic/detail/10128732 https://avg.163.com/topic/detail/10127102 https://avg.163.com/topic/detail/10128699 https://avg.163.com/topic/detail/10128714 https://avg.163.com/topic/detail/10128677 https://avg.163.com/topic/detail/10128661 https://avg.163.com/topic/detail/10128566 https://avg.163.com/topic/detail/10128636 https://avg.163.com/topic/detail/10128611 https://avg.163.com/topic/detail/10128578 https://avg.163.com/topic/detail/10128556 https://avg.163.com/topic/detail/10128542 https://avg.163.com/topic/detail/10128510 https://avg.163.com/topic/detail/10128507 https://avg.163.com/topic/detail/10128488 https://avg.163.com/topic/detail/10128473 https://avg.163.com/topic/detail/10128459 https://avg.163.com/topic/detail/10128445 https://avg.163.com/topic/detail/10128433 https://avg.163.com/topic/detail/10128434 https://avg.163.com/topic/detail/10128412 https://avg.163.com/topic/detail/10128402 https://avg.163.com/topic/detail/10128387 https://avg.163.com/topic/detail/10128364 https://avg.163.com/topic/detail/10128174 https://avg.163.com/topic/detail/10128214 https://avg.163.com/topic/detail/10128326 https://avg.163.com/topic/detail/10128317 https://avg.163.com/topic/detail/10128296 https://avg.163.com/topic/detail/10128295 https://avg.163.com/topic/detail/10128274 https://avg.163.com/topic/detail/10128256 https://avg.163.com/topic/detail/10128250 https://avg.163.com/topic/detail/10128243 https://avg.163.com/topic/detail/10128236 https://avg.163.com/topic/detail/10128234 https://avg.163.com/topic/detail/10128210 https://avg.163.com/topic/detail/10128170 https://avg.163.com/topic/detail/10128178 https://avg.163.com/topic/detail/10128172 https://avg.163.com/topic/detail/10128147 https://avg.163.com/topic/detail/10128123 https://avg.163.com/topic/detail/10128111 https://avg.163.com/topic/detail/10126646 https://avg.163.com/topic/detail/10128080 https://avg.163.com/topic/detail/10128066 https://avg.163.com/topic/detail/10126749 https://avg.163.com/topic/detail/10128057 https://avg.163.com/topic/detail/10127937 https://avg.163.com/topic/detail/10128034 https://avg.163.com/topic/detail/10128032 https://avg.163.com/topic/detail/10128026 https://avg.163.com/topic/detail/10128014 https://avg.163.com/topic/detail/10127994 https://avg.163.com/topic/detail/10127985 https://avg.163.com/topic/detail/10127969 https://avg.163.com/topic/detail/10127962 https://avg.163.com/topic/detail/10127957 https://avg.163.com/topic/detail/10127950 https://avg.163.com/topic/detail/10127937 https://avg.163.com/topic/detail/10127903 https://avg.163.com/topic/detail/10126774 https://avg.163.com/topic/detail/10127859 https://avg.163.com/topic/detail/10126744 https://avg.163.com/topic/detail/10127787 https://avg.163.com/topic/detail/10127773 https://avg.163.com/topic/detail/10127762 https://avg.163.com/topic/detail/10127726 https://avg.163.com/topic/detail/10127697 https://avg.163.com/topic/detail/10127694 https://avg.163.com/topic/detail/10127652 https://avg.163.com/topic/detail/10127646 https://avg.163.com/topic/detail/10127596 https://avg.163.com/topic/detail/10127579 https://avg.163.com/topic/detail/10127570 https://avg.163.com/topic/detail/10127550 https://avg.163.com/topic/detail/10126981 https://avg.163.com/topic/detail/10127466 https://avg.163.com/topic/detail/10126768 https://avg.163.com/topic/detail/10127421 https://avg.163.com/topic/detail/10126651 https://avg.163.com/topic/detail/10127390 https://avg.163.com/topic/detail/10127385 https://avg.163.com/topic/detail/10127358 https://avg.163.com/topic/detail/10127301 https://avg.163.com/topic/detail/10127313 https://avg.163.com/topic/detail/10127265 https://avg.163.com/topic/detail/10127277 https://avg.163.com/topic/detail/10127262 https://avg.163.com/topic/detail/10127250 https://avg.163.com/topic/detail/10127234 https://avg.163.com/topic/detail/10127240 https://avg.163.com/topic/detail/10127226 https://avg.163.com/topic/detail/10127219 https://avg.163.com/topic/detail/10126633 https://avg.163.com/topic/detail/10127205 https://avg.163.com/topic/detail/10127192 https://avg.163.com/topic/detail/10127180 https://avg.163.com/topic/detail/10127162 https://avg.163.com/topic/detail/10127132 https://avg.163.com/topic/detail/10127135 https://avg.163.com/topic/detail/10127122 https://avg.163.com/topic/detail/10127125 https://avg.163.com/topic/detail/10127101 https://avg.163.com/topic/detail/10127102 https://avg.163.com/topic/detail/10127099 https://avg.163.com/topic/detail/10126647 https://avg.163.com/topic/detail/10126649 https://avg.163.com/topic/detail/10127028 https://avg.163.com/topic/detail/10127040 https://avg.163.com/topic/detail/10127011 https://avg.163.com/topic/detail/10126984 https://avg.163.com/topic/detail/10126981 https://avg.163.com/topic/detail/10126946 https://avg.163.com/topic/detail/10126962 https://avg.163.com/topic/detail/10126938 https://avg.163.com/topic/detail/10126959 https://avg.163.com/topic/detail/10126939 https://avg.163.com/topic/detail/10126921 https://avg.163.com/topic/detail/10126583 https://avg.163.com/topic/detail/10126878 https://avg.163.com/topic/detail/10126874 https://avg.163.com/topic/detail/10126854 https://avg.163.com/topic/detail/10126839 https://avg.163.com/topic/detail/10126834 https://avg.163.com/topic/detail/10126829 https://avg.163.com/topic/detail/10126826 https://avg.163.com/topic/detail/10126821 https://avg.163.com/topic/detail/10126630 https://avg.163.com/topic/detail/10126800 https://avg.163.com/topic/detail/10126784 https://avg.163.com/topic/detail/10126787 https://avg.163.com/topic/detail/10126781 https://avg.163.com/topic/detail/10126780 https://avg.163.com/topic/detail/10126779 https://avg.163.com/topic/detail/10126777 https://avg.163.com/topic/detail/10126774 https://avg.163.com/topic/detail/10126773 https://avg.163.com/topic/detail/10126771 https://avg.163.com/topic/detail/10126769 https://avg.163.com/topic/detail/10126768 https://avg.163.com/topic/detail/10126762 https://avg.163.com/topic/detail/10126753 https://avg.163.com/topic/detail/10126567 https://avg.163.com/topic/detail/10126750 https://avg.163.com/topic/detail/10126749 https://avg.163.com/topic/detail/10126748 https://avg.163.com/topic/detail/10126746 https://avg.163.com/topic/detail/10126747 https://avg.163.com/topic/detail/10126740 https://avg.163.com/topic/detail/10126745 https://avg.163.com/topic/detail/10126744 https://avg.163.com/topic/detail/10126743 https://avg.163.com/topic/detail/10126742 https://avg.163.com/topic/detail/10126741 https://avg.163.com/topic/detail/10126495 https://avg.163.com/topic/detail/10126596 https://avg.163.com/topic/detail/10126738 https://avg.163.com/topic/detail/10126729 https://avg.163.com/topic/detail/10126717 https://avg.163.com/topic/detail/10126727 https://avg.163.com/topic/detail/10126719 https://avg.163.com/topic/detail/10126726 https://avg.163.com/topic/detail/10126724 https://avg.163.com/topic/detail/10126725 https://avg.163.com/topic/detail/10126723 https://avg.163.com/topic/detail/10126722 https://avg.163.com/topic/detail/10126721 https://avg.163.com/topic/detail/10126720 https://avg.163.com/topic/detail/10126718 https://avg.163.com/topic/detail/10126705 https://avg.163.com/topic/detail/10126703 https://avg.163.com/topic/detail/10126679 https://avg.163.com/topic/detail/10126678 https://avg.163.com/topic/detail/10126677 https://avg.163.com/topic/detail/10126676 https://avg.163.com/topic/detail/10126675 https://avg.163.com/topic/detail/10126674 https://avg.163.com/topic/detail/10126671 https://avg.163.com/topic/detail/10126672 https://avg.163.com/topic/detail/10126670 https://avg.163.com/topic/detail/10126664 https://avg.163.com/topic/detail/10126663 https://avg.163.com/topic/detail/10126652 https://avg.163.com/topic/detail/10126651 https://avg.163.com/topic/detail/10126650 https://avg.163.com/topic/detail/10126647 https://avg.163.com/topic/detail/10126618 https://avg.163.com/topic/detail/10126573 https://avg.163.com/topic/detail/10126555 https://avg.163.com/topic/detail/10126645 https://avg.163.com/topic/detail/10126638 https://avg.163.com/topic/detail/10126644 https://avg.163.com/topic/detail/10126643 https://avg.163.com/topic/detail/10126642 https://avg.163.com/topic/detail/10126640 https://avg.163.com/topic/detail/10126641 https://avg.163.com/topic/detail/10126639 https://avg.163.com/topic/detail/10126636 https://avg.163.com/topic/detail/10126635 https://avg.163.com/topic/detail/10126632 https://avg.163.com/topic/detail/10126633 https://avg.163.com/topic/detail/10126634 https://avg.163.com/topic/detail/10126630 https://avg.163.com/topic/detail/10126629 https://avg.163.com/topic/detail/10126631 https://avg.163.com/topic/detail/10126628 https://avg.163.com/topic/detail/10126489 https://avg.163.com/topic/detail/10126627 https://avg.163.com/topic/detail/10126626 https://avg.163.com/topic/detail/10126624 https://avg.163.com/topic/detail/10126621 https://avg.163.com/topic/detail/10126620 https://avg.163.com/topic/detail/10126521 https://avg.163.com/topic/detail/10126618 https://avg.163.com/topic/detail/10126617 https://avg.163.com/topic/detail/10126615 https://avg.163.com/topic/detail/10126612 https://avg.163.com/topic/detail/10126604 https://avg.163.com/topic/detail/10126601 https://avg.163.com/topic/detail/10126600 https://avg.163.com/topic/detail/10126599 https://avg.163.com/topic/detail/10126598 https://avg.163.com/topic/detail/10126597 https://avg.163.com/topic/detail/10126565 https://avg.163.com/topic/detail/10126596 https://avg.163.com/topic/detail/10126595 https://avg.163.com/topic/detail/10126594 https://avg.163.com/topic/detail/10126593 https://avg.163.com/topic/detail/10126554 https://avg.163.com/topic/detail/10126592 https://avg.163.com/topic/detail/10126591 https://avg.163.com/topic/detail/10126587 https://avg.163.com/topic/detail/10126589 https://avg.163.com/topic/detail/10126588 https://avg.163.com/topic/detail/10126585 https://avg.163.com/topic/detail/10126586 https://avg.163.com/topic/detail/10126584 https://avg.163.com/topic/detail/10126583 https://avg.163.com/topic/detail/10126582 https://avg.163.com/topic/detail/10126579 https://avg.163.com/topic/detail/10126581 https://avg.163.com/topic/detail/10126580 https://avg.163.com/topic/detail/10126578 https://avg.163.com/topic/detail/10126577 https://avg.163.com/topic/detail/10126576 https://avg.163.com/topic/detail/10126574 https://avg.163.com/topic/detail/10126575 https://avg.163.com/topic/detail/10126573 https://avg.163.com/topic/detail/10126572 https://avg.163.com/topic/detail/10126571 https://avg.163.com/topic/detail/10126570 https://avg.163.com/topic/detail/10126569 https://avg.163.com/topic/detail/10126568 https://avg.163.com/topic/detail/10126567 https://avg.163.com/topic/detail/10126566 https://avg.163.com/topic/detail/10126565 https://avg.163.com/topic/detail/10126564 https://avg.163.com/topic/detail/10126563 https://avg.163.com/topic/detail/10126562 https://avg.163.com/topic/detail/10126561 https://avg.163.com/topic/detail/10126560 https://avg.163.com/topic/detail/10126559 https://avg.163.com/topic/detail/10126557 https://avg.163.com/topic/detail/10126558 https://avg.163.com/topic/detail/10126556 https://avg.163.com/topic/detail/10126555 https://avg.163.com/topic/detail/10126554 https://avg.163.com/topic/detail/10126553 https://avg.163.com/topic/detail/10126483 https://avg.163.com/topic/detail/10126552 https://avg.163.com/topic/detail/10126551 https://avg.163.com/topic/detail/10126546 https://avg.163.com/topic/detail/10126550 https://avg.163.com/topic/detail/10126549 https://avg.163.com/topic/detail/10126548 https://avg.163.com/topic/detail/10126547 https://avg.163.com/topic/detail/10126545 https://avg.163.com/topic/detail/10126544 https://avg.163.com/topic/detail/10126543 https://avg.163.com/topic/detail/10126542 https://avg.163.com/topic/detail/10126541 https://avg.163.com/topic/detail/10126540 https://avg.163.com/topic/detail/10126539选项包括-c, -d, -m, -g, -G, -s, -u以及-o等,这些选项的意义与useradd命令中的选项一样,可以为用户指定新的资源值。

另外,有些系统可以使用选项:-l 新用户名

这个选项指定一个新的账号,即将原来的用户名改为新的用户名。

例如:

# usermod -s /bin/ksh -d /home/z –g developer sam

此命令将用户sam的登录Shell修改为ksh,主目录改为/home/z,用户组改为developer。

4、用户口令的管理

用户管理的一项重要内容是用户口令的管理。用户账号刚创建时没有口令,但是被系统锁定,无法使用,必须为其指定口令后才可以使用,即使是指定空口令。

指定和修改用户口令的Shell命令是passwd。超级用户可以为自己和其他用户指定口令,普通用户只能用它修改自己的口令。命令的格式为:

passwd 选项 用户名

可使用的选项:

  • -l 锁定口令,即禁用账号。
  • -u 口令解锁。
  • -d 使账号无口令。
  • -f 强迫用户下次登录时修改口令。

如果默认用户名,则修改当前用户的口令。

例如,假设当前用户是sam,则下面的命令修改该用户自己的口令:

$ passwd
Old password:******
New password:*******
Re-enter new password:*******

如果是超级用户,可以用下列形式指定任何用户的口令:

# passwd sam
New password:*******
Re-enter new password:*******

普通用户修改自己的口令时,passwd命令会先询问原口令,验证后再要求用户输入两遍新口令,如果两次输入的口令一致,则将这个口令指定给用户;而超级用户为用户指定口令时,就不需要知道原口令。

为了系统安全起见,用户应该选择比较复杂的口令,例如最好使用8位长的口令,口令中包含有大写、小写字母和数字,并且应该与姓名、生日等不相同。

为用户指定空口令时,执行下列形式的命令:

# passwd -d sam

此命令将用户 sam 的口令删除,这样用户 sam 下一次登录时,系统就不再允许该用户登录了。

passwd 命令还可以用 -l(lock) 选项锁定某一用户,使其不能登录,例如:

# passwd -l sam


二、Linux系统用户组的管理

每个用户都有一个用户组,系统可以对一个用户组中的所有用户进行集中管理。不同Linux 系统对用户组的规定有所不同,如Linux下的用户属于与它同名的用户组,这个用户组在创建用户时同时创建。

用户组的管理涉及用户组的添加、删除和修改。组的增加、删除和修改实际上就是对/etc/group文件的更新。

1、增加一个新的用户组使用groupadd命令。其格式如下:

groupadd 选项 用户组

可以使用的选项有:

  • -g GID 指定新用户组的组标识号(GID)。
  • -o 一般与-g选项同时使用,表示新用户组的GID可以与系统已有用户组的GID相同。
实例1:

# groupadd group1

此命令向系统中增加了一个新组group1,新组的组标识号是在当前已有的最大组标识号的基础上加1。

实例2:

# groupadd -g 101 group2

此命令向系统中增加了一个新组group2,同时指定新组的组标识号是101。

2、如果要删除一个已有的用户组,使用groupdel命令,其格式如下:

groupdel 用户组

例如:

# groupdel group1

此命令从系统中删除组group1。

3、修改用户组的属性使用groupmod命令。其语法如下:

groupmod 选项 用户组

常用的选项有:

  • -g GID 为用户组指定新的组标识号。
  • -o 与-g选项同时使用,用户组的新GID可以与系统已有用户组的GID相同。
  • -n新用户组 将用户组的名字改为新名字
实例1:

# groupmod -g 102 group2

此命令将组group2的组标识号修改为102。

实例2:

# groupmod –g 10000 -n group3 group2

此命令将组group2的标识号改为10000,组名修改为group3。

4、如果一个用户同时属于多个用户组,那么用户可以在用户组之间切换,以便具有其他用户组的权限。

用户可以在登录后,使用命令newgrp切换到其他用户组,这个命令的参数就是目的用户组。例如:

$ newgrp root

这条命令将当前用户切换到root用户组,前提条件是root用户组确实是该用户的主组或附加组。类似于用户账号的管理,用户组的管理也可以通过集成的系统管理工具来完成。


三、与用户账号有关的系统文件

完成用户管理的工作有许多种方法,但是每一种方法实际上都是对有关的系统文件进行修改。

与用户和用户组相关的信息都存放在一些系统文件中,这些文件包括/etc/passwd, /etc/shadow, /etc/group等。

下面分别介绍这些文件的内容。

1、/etc/passwd文件是用户管理工作涉及的最重要的一个文件。

Linux系统中的每个用户都在/etc/passwd文件中有一个对应的记录行,它记录了这个用户的一些基本属性。

这个文件对所有用户都是可读的。它的内容类似下面的例子:

# cat /etc/passwd

root:x:0:0:Superuser:/:
daemon:x:1:1:System daemons:/etc:
bin:x:2:2:Owner of system commands:/bin:
sys:x:3:3:Owner of system files:/usr/sys:
adm:x:4:4:System accounting:/usr/adm:
uucp:x:5:5:UUCP administrator:/usr/lib/uucp:
auth:x:7:21:Authentication administrator:/tcb/files/auth:
cron:x:9:16:Cron daemon:/usr/spool/cron:
listen:x:37:4:Network daemon:/usr/net/nls:
lp:x:71:18:Printer administrator:/usr/spool/lp:
sam:x:200:50:Sam san:/home/sam:/bin/sh

从上面的例子我们可以看到,/etc/passwd中一行记录对应着一个用户,每行记录又被冒号(:)分隔为7个字段,其格式和具体含义如下:

用户名:口令:用户标识号:组标识号:注释性描述:主目录:登录Shell

1)"用户名"是代表用户账号的字符串。

通常长度不超过8个字符,并且由大小写字母和/或数字组成。登录名中不能有冒号(:),因为冒号在这里是分隔符。

为了兼容起见,登录名中最好不要包含点字符(.),并且不使用连字符(-)和加号(+)打头。

2)“口令”一些系统中,存放着加密后的用户口令字。

虽然这个字段存放的只是用户口令的加密串,不是明文,但是由于/etc/passwd文件对所有用户都可读,所以这仍是一个安全隐患。因此,现在许多Linux 系统(如SVR4)都使用了shadow技术,把真正的加密后的用户口令字存放到/etc/shadow文件中,而在/etc/passwd文件的口令字段中只存放一个特殊的字符,例如“x”或者“*”。

3)“用户标识号”是一个整数,系统内部用它来标识用户。

一般情况下它与用户名是一一对应的。如果几个用户名对应的用户标识号是一样的,系统内部将把它们视为同一个用户,但是它们可以有不同的口令、不同的主目录以及不同的登录Shell等。

通常用户标识号的取值范围是0~65 535。0是超级用户root的标识号,1~99由系统保留,作为管理账号,普通用户的标识号从100开始。在Linux系统中,这个界限是500。

4)“组标识号”字段记录的是用户所属的用户组。

赞(0)
未经允许不得转载:171主机测评 » Linux 用户和用户组管理65658
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址