centos7用戶多次登錄失敗被鎖定、sudo權限管理、添加用戶報錯處理


centos7用戶多次登錄失敗被鎖定、sudo權限管理、添加用戶報錯處理
 
一、Account locked due to failed logins
解決:
方法一:
使用root用戶登陸后執行:
pam_tally2 --user=username --reset
 
方法二:
usermod -U
 
二、sudo權限賦予
Linux中普通用戶用sudo執行命令時報”xxx is not in the sudoers file.This incident will be reported”錯誤,解決方法就是在/etc/sudoers文件里給該用戶添加權限。如下:
1.切換到root用戶下
  方法為直接在命令行輸入:su,然后輸入密碼(即你的登錄密碼,且密碼默認不可見)。
2./etc/sudoers文件默認是只讀的,對root來說也是,因此需先添加sudoers文件的寫權限,命令是:
即執行操作:
chmod u+w /etc/sudoers
 
3.編輯sudoers文件
即執行:
vi /etc/sudoers
 
找到這行 root ALL=(ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (這里的xxx是你的用戶名)
ps:這里說下你可以sudoers添加下面四行中任意一條
youuser ALL=(ALL) ALL %youuser ALL=(ALL) ALL youuser ALL=(ALL) NOPASSWD: ALL %youuser ALL=(ALL) NOPASSWD: ALL
 
第一行:允許用戶youuser執行sudo命令(需要輸入密碼).
第二行:允許用戶組youuser里面的用戶執行sudo命令(需要輸入密碼).
第三行:允許用戶youuser執行sudo命令,並且在執行的時候不輸入密碼.
第四行:允許用戶組youuser里面的用戶執行sudo命令,並且在執行的時候不輸入密碼.
4.撤銷sudoers文件寫權限,命令:
chmod u-w /etc/sudoers
 
三、添加Apache用戶和組,但此時報錯了, groupadd :cannot open /etc/group
1、修改文件權限
chattr -i /etc/gshadow chattr -i /etc/shadow chattr -i /etc/group chattr -i /etc/passwd
 
2、添加用戶和組
groupadd apache useradd -g apache apache
 
 
四、解決centos中ssh登錄時Warning:Permanently added (RSA) to the list of known hosts的警告
vim /etc/ssh/ssh_config(master和slave1都需要設置)
 
找到#StrictHostKeyChecking ask去掉注釋,並把ask改為no即可
五、su后出現’incorrect password’問題的解決
檢查/bin/su文件屬性 若為’rwxr-xr-x’ 則文件屬性不正確,修改屬性為’rwsr-xr-x’
chomod u+s /bin/su
 
六、創建用戶
1.新建用戶
adduser testuser //新建testuser 用戶 passwd testuser //給testuser 用戶設置密碼
 
 
2.建工作組
groupadd testgroup //新建test工作組
 
3.新建用戶同時增加工作組
useradd -g testgroup testuser //新建testuser用戶並增加到testgroup工作組
 
//注::-g 所屬組 -d 家目錄 -s 所用的SHELL
4.給已有的用戶增加工作組
usermod -G groupname username
 
5.臨時關閉
在/etc/shadow文件中屬於該用戶的行的第二個字段(密碼)前面加上就可以了。想恢復該用戶,去掉即可
//或者使用如下命令關閉用戶賬號: passwd testuser –l //重新釋放: passwd testuser –u
 
6.永久性刪除用戶賬號
userdel testuser groupdel testgroup usermod –G testgroup testuser //(強制刪除該用戶的主目錄和主目錄下的所有文件和子目錄)
 
7.顯示用戶信息
id user cat /etc/passwd
 
補充:查看用戶和用戶組的方法
用戶列表文件:/etc/passwd 用戶組列表文件:/etc/group 查看系統中有哪些用戶:cut -d : -f 1 /etc/passwd 查看可以登錄系統的用戶:cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1 查看用戶操作:w命令(需要root權限) 查看某一用戶:w 用戶名 查看登錄用戶:who 查看用戶登錄歷史記錄:last
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM