添加用户并重置密码
[root@VM-0-17-centos software]# useradd microxiang
[root@VM-0-17-centos software]# passwd microxiang
Changing password for user microxiang.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
添加用户到sudoers
修改/etc/sudoers文件权限
进入超级用户,因为没有写权限,所以要先把写权限加上
chmod u+w /etc/sudoers
编辑/etc/sudoers文件
vim /etc/sudoers
找到这一 行:"root ALL=(ALL) ALL"在起下面添加"microxiang ALL=(ALL) ALL"(microxiang是用户名),然后保存。
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
microxiang ALL=(ALL) ALL
注:如果不想每次都输入密码,可以修改后不需要每次都输入密码了。
microxiang ALL=(ALL) NOPASSWD: ALL
最后恢复没有写权限模式
撤销文件的写权限
chmod u-w /etc/sudoers
完整操作过程如下:
[root@VM-0-17-centos software]# useradd microxiang
[root@VM-0-17-centos software]# passwd microxiang
Changing password for user microxiang.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@VM-0-17-centos software]# chmod u+w /etc/sudoers
[root@VM-0-17-centos software]# vim /etc/sudoers
[root@VM-0-17-centos software]# chmod u-w /etc/sudoers
[root@VM-0-17-centos software]#
评论 (0)