天下事有难易乎?为之,则难者亦易矣;不为,则易者亦难矣。

Linux Centos7下创建sudo用户 拥有root用户的操作权限

往事如烟 2079次浏览 0个评论

记录下个人的操作步骤:

使用root用户登录,然后添加一个用户matu,然后修改密码,两次即可。

[root@iZ2ze7wyymbgnonfk0zn48Z ~]# useradd matu
[root@iZ2ze7wyymbgnonfk0zn48Z ~]# passwd matu
Changing password for user matu.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@iZ2ze7wyymbgnonfk0zn48Z ~]# 

切换到matu用户,输入密码,切换到matu用户,然后尝试使用sudo 执行编辑文件。(也可以直接使用sudo su matu切换到matu用户)

[matu@iZ2ze7wyymbgnonfk0zn48Z root]$ ssh matu@47.95.247.157
The authenticity of host '47.95.247.157 (47.95.247.157)' can't be established.
ECDSA key fingerprint is SHA256:mX4Fl8+VNKHBZKImxo3Nq9MAuG7HnXW3CywGS1jQmC8.
ECDSA key fingerprint is MD5:a7:98:ad:5f:ed:62:58:52:2f:ad:97:13:b0:18:34:ef.
Are you sure you want to continue connecting (yes/no)? yes                
Warning: Permanently added '47.95.247.157' (ECDSA) to the list of known hosts.
matu@47.95.247.157's password: 
Last login: Tue Oct 27 18:42:12 2020
 
Welcome to Alibaba Cloud Elastic Compute Service !

在使用sudo口令执行超管口令时,提示不在超管配置文件中,需要手动添加。(执行sudo matu时提示错误,请使用sudo su matu)

[root@iZ2ze7wyymbgnonfk0zn48Z ~]# sudo su matu
 
[matu@iZ2ze7wyymbgnonfk0zn48Z root]$ sudo vim /etc/sudoers
 
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
 
    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.
 
[sudo] password for matu: 
matu is not in the sudoers file.  This incident will be reported.

这里需要编辑配置文件/etc/sudoers,但是目前的用户没有超级管理员文件中,需要切换回root用户来修改配置文件,或者直接导出配置文件到本地,手动修改。这里直接导出(这个配置文件貌似对root也是readonly)

直接打开编辑。

找到这行,直接复制一行,同时修改为自己的用户名

 

root	ALL=(ALL) 	ALL
matu	ALL=(ALL) 	ALL

如果不行每次使用sudo都输入密码的话,可以把ALL换成NOPASSWD:ALL即可。我这里修改为不输入密码。

root	ALL=(ALL) 	ALL
matu	ALL=(ALL) 	NOPASSWD: ALL

然后保存修改后的文件并直接上传,覆盖之前的文件。再次指行之前sudo vim编辑命令,可以看到已经拥有了root的操作权限。


ITZOO版权所有丨如未注明 , 均为原创丨转载请注明来自IT乐园 ->Linux Centos7下创建sudo用户 拥有root用户的操作权限
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址