买了一台阿里云服务器,准备用来做服务使用,但是由于只有root账号,总感觉安全性上可能会有问题,因此这里建立一个普通账户并授权,以后都用这个用户进行操作。

创建新用户

# adduser youruser
# passwd youruser
Changing password for user youruser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

授权

这里需要给新建的用户赋予root权限,否则后面操作docker很不方便

# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz
# chmod -v u+w /etc/sudoers
mode of '/etc/sudoers' changed from 0440 (r--r-----) to 0640 (rw-r-----)
# vim /etc/sudoers

把用户加入sudo组

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
youruser ALL=(ALL) ALL #这个是新用户
# chmod -v u-w /etc/sudoers
mode of '/etc/sudoers' changed from 0640 (rw-r-----) to 0440 (r--r-----)

切换用户时后,发现已经有权限了


$ sudo su

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 youruser:
#

但是还有一点是需要输入密码,因此还需要配置一下免密sudo

youruser           ALL=(ALL)                NOPASSWD: ALL

这样就配好了用户,由于是个人使用,就不配置用户组了

标签: etc, centos, 用户, password, sudoers, 新建, 授权, youruser

相关文章推荐

添加新评论,含*的栏目为必填