Hello World

Linux之用户和用户组管理

 

 

                                                                     用户配置文件

一 用户信息文件

 

 

 

 

[root@localhost ~]# ll /etc/passwd
-rw-r--r-- 1 root root 1336 Feb  6 15:18 /etc/passwd
[root@localhost ~]# ll /etc/shadow
---------- 1 root root 930 Feb  6 15:18 /etc/shadow     #权限为000,这个文件极为重要

 

 

 

 

 

 

 二 影子文件

 

 

 展示:

 

 

 

 

 

 

 

 三 组信息文件

 

 

 

 

 

                                                                

                                                         用户管理的相关文件

 

 

 

 

 

[root@localhost ~]# cd /var/spool/mail/       #默认路径
[root@localhost mail]# ls
 Tom    user

 

 

 

[root@localhost user]# cd /etc/skel/
[root@localhost skel]# vi warningtest.txext    #写入的是:请注意操作规范
[root@localhost skel]# ls -a
.  ..  .bash_logout  .bash_profile  .bashrc  warningtest.txext

#---新添加个用户
[root@localhost skel]# useradd user1
[root@localhost skel]# passwd user1    #要设置密码
Changing password for user user1.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost skel]# cd /home/user1/
[root@localhost user1]# ls          
warningtest.txt                               #随着新用户的创建,此文件也随之创建

 

 

                                                                                

                                                            用户管理命令

 

 

 

 

一 用户添加命令

 

 

 

 

 

 

 

 

 

 

 

 

 

 

二 修改用户密码

 

 

 

 

 

 

 

 

 

 

 

 

 

三 修改用户信息usermod;修改用户密码状态chage

 

 

 

[root@localhost ~]# usermod -u 3336 -c 'test 修改' user

[root@localhost ~]# cat /etc/passwd/
user:x:3336:1304:test 修改:/home/user:/bin/bash

 

 

 

 

 

 

四 删除用户userdel;用户切换命令su

 

 

 

 

 

 

 

 

 

 

#---------使用了错误的切换: su root
#-------- 正确的:  su - root 

[user@localhost ~]$ whoami   #普通用户环境下
user
[user@localhost ~]$ su root    #错误的切换 su root
Password: 
[root@localhost user]# whoami
root
[root@localhost user]# env    #环境变量
SHELL=/bin/bash
USER=user                  #依然是: 普通用户user
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/user/.local/bin:/home/user/bin
MAIL=/var/spool/mail/user     #邮箱依然是 user的
PWD=/home/user
LOGNAME=user

 

 

 

 

 

                                                                

                                     用户组管理命

 

[root@localhost ~]# groupadd tg
[root@localhost ~]# vi /etc/group
tg:x:3338:

 

 

 

[root@localhost ~]# groupmod -n new_tg tg
[root@localhost ~]# vi /etc/group
new_tg:x:3338:

 

 

 

[root@localhost ~]# groupadd tg
[root@localhost ~]# useradd -g tg lamp     #初始组
[root@localhost ~]# useradd -G tg lamp1   #附加组
[root@localhost ~]# vi /etc/group
user3:x:3337:
tg:x:3338:lamp1
lamp1:x:3339:

[root@localhost ~]# groupdel tg    #由于有初始组的处在,并不删除 tg
groupdel: cannot remove the primary group of user 'lamp'
[root@localhost ~]# userdel -r lamp   #删除 用户lamp
[root@localhost ~]# groupdel tg    
[root@localhost ~]# vi /etc/group     #OK
user3:x:3337:
lamp1:x:3339:

 

 

 

#--------------- 添加入组格式: gpasswd -a [用户]  [组名]

[root@localhost ~]# gpasswd -a user root
Adding user user to group root
[root@localhost ~]# vi /etc/group
root:x:0:god,user


#------------- 从组中删除
[root@localhost ~]# gpasswd -d user root   
Removing user user from group root
[root@localhost ~]# gpasswd -d god root
Removing user god from group root
[root@localhost ~]# vi /etc/group
root:x:0:

 

posted @ 2017-03-21 19:53  nayike  阅读(231)  评论(0)    收藏  举报

Hello