1. 程式人生 > >【Linux學習六】使用者管理

【Linux學習六】使用者管理

環境
  虛擬機器:VMware 10
  Linux版本:CentOS-6.5-x86_64
  客戶端:Xshell4
  FTP:Xftp4

一、增加刪除使用者或組
新增使用者
useradd scott
修改使用者密碼
passwd scott(root使用者可以修改所有使用者密碼,普通使用者只可以修改自己的)

[[email protected] ~]# useradd scott
[[email protected] ~]# passwd scott
Changing password for user scott.
New password: 
BAD PASSWORD: it is too simplistic
/systematic BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully.

 

刪除使用者
userdel scott
rm -rf /home/scott
rm -rf /var/spool/mail/scott

新增組share
groupadd share

id命令用於顯示使用者的ID,以及所屬群組的ID
id root

usermod 修改使用者帳號
-c<備註>  修改使用者帳號的備註文字。
-d登入目錄>  修改使用者登入時的目錄。
-e<有效期限>  修改帳號的有效期限。
-f<緩衝天數>  修改在密碼過期後多少天即關閉該帳號。
-g<群組>  修改使用者所屬的群組。
-G<群組>  修改使用者所屬的附加群組。
-l<帳號名稱>  修改使用者帳號名稱。
-L  鎖定使用者密碼,使密碼無效。
-s<shell>  修改使用者登入後所使用的shell。
-u<uid>  修改使用者ID。
-U  解除密碼鎖定

#新增組share
[[email protected] ~]# groupadd share
#檢視使用者和組id
[[email protected] ~]# id scott
uid=500(scott) gid=501(scott) groups=501(scott)
#修改使用者歸屬組
[[email protected] ~]# usermod -G share scott
[[email protected] ~]# id scott
uid=500(scott) gid=501(scott) groups=501(scott),500(share)

 

二、修改許可權和屬組
1.chown 指定檔案的擁有者改為指定的使用者或組

[[email protected] /]# ll |grep "share"
drwxr-xr-x.  2 root root  4096 Dec 22 14:50 share
[[email protected] /]# chown root:share /share
[[email protected] /]# ll |grep "share"
drwxr-xr-x.  2 root share  4096 Dec 22 14:50 share
[[email protected] share]# ll
total 4
-rw-r--r--. 1 root root 3 Dec 22 15:05 1.log
[[email protected] share]# chown :share 1.log
[[email protected] share]# ll
total 4
-rw-r--r--. 1 root share 3 Dec 22 15:05 1.log

 

2.chmod 改變檔案目錄的讀寫執行許可權

字元方式:chmod augo +/-rwx    給所有使用者/屬主/屬組/其他使用者 新增/刪除讀寫執行許可權

數字方式:r=4 w=2 x=1

[[email protected] /]# chmod g+w /share
[[email protected] /]# ll |grep "share"
drwxrwxr-x. 2 root share 4096 Dec 22 14:50 share
[[email protected] /]# chmod o-rx /share
[[email protected] /]# ll |grep "share"
drwxrwx---. 2 root share 4096 Dec 22 14:50 share

 

3.使用者需要重新登入後才能生效