云计算百科
云计算领域专业知识百科平台

Linux 用户和用户组管理79970

Linux 用户和用户组管理

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

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

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

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

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

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

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

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

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

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

useradd 选项 用户名

参数说明:

  • 选项:

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

  • https://avg.163.com/topic/detail/10903267
    https://avg.163.com/topic/detail/10903265
    https://avg.163.com/topic/detail/10903266
    https://avg.163.com/topic/detail/10903263
    https://avg.163.com/topic/detail/10903264
    https://avg.163.com/topic/detail/10903262
    https://avg.163.com/topic/detail/10903261
    https://avg.163.com/topic/detail/10903260
    https://avg.163.com/topic/detail/10903259
    https://avg.163.com/topic/detail/10903257
    https://avg.163.com/topic/detail/10903258
    https://avg.163.com/topic/detail/10903256
    https://avg.163.com/topic/detail/10903255
    https://avg.163.com/topic/detail/10903254
    https://avg.163.com/topic/detail/10903253
    https://avg.163.com/topic/detail/10903252
    https://avg.163.com/topic/detail/10903250
    https://avg.163.com/topic/detail/10903247
    https://avg.163.com/topic/detail/10903249
    https://avg.163.com/topic/detail/10903246
    https://avg.163.com/topic/detail/10903248
    https://avg.163.com/topic/detail/10903245
    https://avg.163.com/topic/detail/10903244
    https://avg.163.com/topic/detail/10903243
    https://avg.163.com/topic/detail/10903241
    https://avg.163.com/topic/detail/10903240
    https://avg.163.com/topic/detail/10903242
    https://avg.163.com/topic/detail/10903238
    https://avg.163.com/topic/detail/10903237
    https://avg.163.com/topic/detail/10903236
    https://avg.163.com/topic/detail/10903235
    https://avg.163.com/topic/detail/10903234
    https://avg.163.com/topic/detail/10903233
    https://avg.163.com/topic/detail/10903232
    https://avg.163.com/topic/detail/10903231
    https://avg.163.com/topic/detail/10903230
    https://avg.163.com/topic/detail/10903228
    https://avg.163.com/topic/detail/10903227
    https://avg.163.com/topic/detail/10903226
    https://avg.163.com/topic/detail/10903224
    https://avg.163.com/topic/detail/10903225
    https://avg.163.com/topic/detail/10903222
    https://avg.163.com/topic/detail/10903223
    https://avg.163.com/topic/detail/10903221
    https://avg.163.com/topic/detail/10903220
    https://avg.163.com/topic/detail/10903219
    https://avg.163.com/topic/detail/10903218
    https://avg.163.com/topic/detail/10903217
    https://avg.163.com/topic/detail/10903216
    https://avg.163.com/topic/detail/10903215
    https://avg.163.com/topic/detail/10903212
    https://avg.163.com/topic/detail/10903214
    https://avg.163.com/topic/detail/10903209
    https://avg.163.com/topic/detail/10903204
    https://avg.163.com/topic/detail/10903203
    https://avg.163.com/topic/detail/10903194
    https://avg.163.com/topic/detail/10903193
    https://avg.163.com/topic/detail/10903192
    https://avg.163.com/topic/detail/10903191
    https://avg.163.com/topic/detail/10903190
    https://avg.163.com/topic/detail/10903188
    https://avg.163.com/topic/detail/10903189
    https://avg.163.com/topic/detail/10903187
    https://avg.163.com/topic/detail/10903186
    https://avg.163.com/topic/detail/10903185
    https://avg.163.com/topic/detail/10903180
    https://avg.163.com/topic/detail/10903176
    https://avg.163.com/topic/detail/10903158
    https://avg.163.com/topic/detail/10903167
    https://avg.163.com/topic/detail/10903166
    https://avg.163.com/topic/detail/10903165
    https://avg.163.com/topic/detail/10903164
    https://avg.163.com/topic/detail/10903163
    https://avg.163.com/topic/detail/10903161
    https://avg.163.com/topic/detail/10903160
    https://avg.163.com/topic/detail/10903162
    https://avg.163.com/topic/detail/10903159
    https://avg.163.com/topic/detail/10903157
    https://avg.163.com/topic/detail/10903156
    https://avg.163.com/topic/detail/10903155
    https://avg.163.com/topic/detail/10903144
    https://avg.163.com/topic/detail/10903143
    https://avg.163.com/topic/detail/10903142
    https://avg.163.com/topic/detail/10903136
    https://avg.163.com/topic/detail/10903135
    https://avg.163.com/topic/detail/10903130
    https://avg.163.com/topic/detail/10903134
    https://avg.163.com/topic/detail/10903133
    https://avg.163.com/topic/detail/10903132
    https://avg.163.com/topic/detail/10903131
    https://avg.163.com/topic/detail/10903129
    https://avg.163.com/topic/detail/10903128
    https://avg.163.com/topic/detail/10903120
    https://avg.163.com/topic/detail/10903113
    https://avg.163.com/topic/detail/10903110
    https://avg.163.com/topic/detail/10903108
    https://avg.163.com/topic/detail/10903109
    https://avg.163.com/topic/detail/10903105
    https://avg.163.com/topic/detail/10903107
    https://avg.163.com/topic/detail/10903106
    https://avg.163.com/topic/detail/10903104
    https://avg.163.com/topic/detail/10903102
    https://avg.163.com/topic/detail/10903101
    https://avg.163.com/topic/detail/10903100
    https://avg.163.com/topic/detail/10903099
    https://avg.163.com/topic/detail/10903095
    https://avg.163.com/topic/detail/10903092
    https://avg.163.com/topic/detail/10903089
    https://avg.163.com/topic/detail/10903082
    https://avg.163.com/topic/detail/10903085
    https://avg.163.com/topic/detail/10903088
    https://avg.163.com/topic/detail/10903086
    https://avg.163.com/topic/detail/10903074
    https://avg.163.com/topic/detail/10903076
    https://avg.163.com/topic/detail/10903075
    https://avg.163.com/topic/detail/10903073
    https://avg.163.com/topic/detail/10903070
    https://avg.163.com/topic/detail/10903066
    https://avg.163.com/topic/detail/10903065
    https://avg.163.com/topic/detail/10903054
    https://avg.163.com/topic/detail/10903060
    https://avg.163.com/topic/detail/10903030
    https://avg.163.com/topic/detail/10903035
    https://avg.163.com/topic/detail/10903034
    https://avg.163.com/topic/detail/10903033
    https://avg.163.com/topic/detail/10903032
    https://avg.163.com/topic/detail/10903031
    https://avg.163.com/topic/detail/10903028
    https://avg.163.com/topic/detail/10903029
    https://avg.163.com/topic/detail/10903027
    https://avg.163.com/topic/detail/10903026
    https://avg.163.com/topic/detail/10903025
    https://avg.163.com/topic/detail/10903024
    https://avg.163.com/topic/detail/10903023
    https://avg.163.com/topic/detail/10903020
    https://avg.163.com/topic/detail/10903014
    https://avg.163.com/topic/detail/10903012
    https://avg.163.com/topic/detail/10903009
    https://avg.163.com/topic/detail/10903010
    https://avg.163.com/topic/detail/10903008
    https://avg.163.com/topic/detail/10903002
    https://avg.163.com/topic/detail/10903004
    https://avg.163.com/topic/detail/10903000
    https://avg.163.com/topic/detail/10902999
    https://avg.163.com/topic/detail/10902998
    https://avg.163.com/topic/detail/10902982
    https://avg.163.com/topic/detail/10902981
    https://avg.163.com/topic/detail/10902979
    https://avg.163.com/topic/detail/10902980
    https://avg.163.com/topic/detail/10902978
    https://avg.163.com/topic/detail/10902975
    https://avg.163.com/topic/detail/10902976
    https://avg.163.com/topic/detail/10902977
    https://avg.163.com/topic/detail/10902974
    https://avg.163.com/topic/detail/10902973
    https://avg.163.com/topic/detail/10902970
    https://avg.163.com/topic/detail/10902972
    https://avg.163.com/topic/detail/10902971
    https://avg.163.com/topic/detail/10902969
    https://avg.163.com/topic/detail/10902968
    https://avg.163.com/topic/detail/10902967
    https://avg.163.com/topic/detail/10902966
    https://avg.163.com/topic/detail/10902965
    https://avg.163.com/topic/detail/10902964
    https://avg.163.com/topic/detail/10902963
    https://avg.163.com/topic/detail/10902961
    https://avg.163.com/topic/detail/10902962
    https://avg.163.com/topic/detail/10902951
    https://avg.163.com/topic/detail/10902946
    https://avg.163.com/topic/detail/10902945
    https://avg.163.com/topic/detail/10902944
    https://avg.163.com/topic/detail/10902943
    https://avg.163.com/topic/detail/10902942
    https://avg.163.com/topic/detail/10902941
    https://avg.163.com/topic/detail/10902940
    https://avg.163.com/topic/detail/10902939
    https://avg.163.com/topic/detail/10902917
    https://avg.163.com/topic/detail/10902928
    https://avg.163.com/topic/detail/10902924
    https://avg.163.com/topic/detail/10902921
    https://avg.163.com/topic/detail/10902920
    https://avg.163.com/topic/detail/10902918
    https://avg.163.com/topic/detail/10902919
    https://avg.163.com/topic/detail/10902916
    https://avg.163.com/topic/detail/10902915
    https://avg.163.com/topic/detail/10902913
    https://avg.163.com/topic/detail/10902912
    https://avg.163.com/topic/detail/10902911
    https://avg.163.com/topic/detail/10902910
    https://avg.163.com/topic/detail/10902909
    https://avg.163.com/topic/detail/10902907
    https://avg.163.com/topic/detail/10902908
    https://avg.163.com/topic/detail/10902891
    https://avg.163.com/topic/detail/10902890
    https://avg.163.com/topic/detail/10902889
    https://avg.163.com/topic/detail/10902888
    https://avg.163.com/topic/detail/10902887
    https://avg.163.com/topic/detail/10902886
    https://avg.163.com/topic/detail/10902884
    https://avg.163.com/topic/detail/10902885
    https://avg.163.com/topic/detail/10902879
    https://avg.163.com/topic/detail/10902883
    https://avg.163.com/topic/detail/10902881
    https://avg.163.com/topic/detail/10902880
    https://avg.163.com/topic/detail/10902876
    https://avg.163.com/topic/detail/10902877
    https://avg.163.com/topic/detail/10902873
    https://avg.163.com/topic/detail/10902872
    https://avg.163.com/topic/detail/10902867
    https://avg.163.com/topic/detail/10902862
    https://avg.163.com/topic/detail/10902857
    https://avg.163.com/topic/detail/10902700
    https://avg.163.com/topic/detail/10902701
    https://avg.163.com/topic/detail/10902860
    https://avg.163.com/topic/detail/10902859
    https://avg.163.com/topic/detail/10902858
    https://avg.163.com/topic/detail/10902856
    https://avg.163.com/topic/detail/10902855
    https://avg.163.com/topic/detail/10902854
    https://avg.163.com/topic/detail/10902853
    https://avg.163.com/topic/detail/10902828
    https://avg.163.com/topic/detail/10902837
    https://avg.163.com/topic/detail/10902833
    https://avg.163.com/topic/detail/10902834
    https://avg.163.com/topic/detail/10902821
    https://avg.163.com/topic/detail/10902819
    https://avg.163.com/topic/detail/10902813
    https://avg.163.com/topic/detail/10902809
    https://avg.163.com/topic/detail/10902808
    https://avg.163.com/topic/detail/10902807
    https://avg.163.com/topic/detail/10902806
    https://avg.163.com/topic/detail/10902805
    https://avg.163.com/topic/detail/10902798
    https://avg.163.com/topic/detail/10902804
    https://avg.163.com/topic/detail/10902803
    https://avg.163.com/topic/detail/10902802
    https://avg.163.com/topic/detail/10902801
    https://avg.163.com/topic/detail/10902800
    https://avg.163.com/topic/detail/10902799
    https://avg.163.com/topic/detail/10902797
    https://avg.163.com/topic/detail/10902796
    https://avg.163.com/topic/detail/10902795
    https://avg.163.com/topic/detail/10902794
    https://avg.163.com/topic/detail/10902785
    https://avg.163.com/topic/detail/10902775
    https://avg.163.com/topic/detail/10902782
    https://avg.163.com/topic/detail/10902774
    https://avg.163.com/topic/detail/10902773
    https://avg.163.com/topic/detail/10902772
    https://avg.163.com/topic/detail/10902769
    https://avg.163.com/topic/detail/10902767
    https://avg.163.com/topic/detail/10902765
    https://avg.163.com/topic/detail/10902768
    https://avg.163.com/topic/detail/10902763
    https://avg.163.com/topic/detail/10902738
    https://avg.163.com/topic/detail/10902766
    https://avg.163.com/topic/detail/10902764
    https://avg.163.com/topic/detail/10902761
    https://avg.163.com/topic/detail/10902762
    https://avg.163.com/topic/detail/10902758
    https://avg.163.com/topic/detail/10902757
    https://avg.163.com/topic/detail/10902749
    https://avg.163.com/topic/detail/10902742
    https://avg.163.com/topic/detail/10902741
    https://avg.163.com/topic/detail/10902739
    https://avg.163.com/topic/detail/10902737
    https://avg.163.com/topic/detail/10902736
    https://avg.163.com/topic/detail/10902734
    https://avg.163.com/topic/detail/10902735
    https://avg.163.com/topic/detail/10902727
    https://avg.163.com/topic/detail/10902722
    https://avg.163.com/topic/detail/10902716
    https://avg.163.com/topic/detail/10902715
    https://avg.163.com/topic/detail/10902714
    https://avg.163.com/topic/detail/10902713
    https://avg.163.com/topic/detail/10902712
    https://avg.163.com/topic/detail/10902711
    https://avg.163.com/topic/detail/10902710
    https://avg.163.com/topic/detail/10902709
    https://avg.163.com/topic/detail/10902705
    https://avg.163.com/topic/detail/10902708
    https://avg.163.com/topic/detail/10902707
    https://avg.163.com/topic/detail/10902703
    https://avg.163.com/topic/detail/10902704
    https://avg.163.com/topic/detail/10902702
    https://avg.163.com/topic/detail/10902706
    https://avg.163.com/topic/detail/10902701
    https://avg.163.com/topic/detail/10902700
    https://avg.163.com/topic/detail/10902699
    https://avg.163.com/topic/detail/10902697
    https://avg.163.com/topic/detail/10902698
    https://avg.163.com/topic/detail/10902686
    https://avg.163.com/topic/detail/10902680
    https://avg.163.com/topic/detail/10902678
    https://avg.163.com/topic/detail/10902665

    指定新账号的登录名。

实例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 选项 用户名

常用的选项包括-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,则下面的命令修改该用户自己的口令:

赞(0)
未经允许不得转载:网硕互联帮助中心 » Linux 用户和用户组管理79970
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!