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
 

原文地址:https://www.cnblogs.com/wangboyu/p/14333814.html