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

5 篇文章 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的操作权限。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

终码一生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值