创建用户

useradd devops

设置密码:

passwd username

授权sudo

授权sudo权限,需要修改sudoers文件。文件位置在/etc/sudoers,也可以用whereis sudoers查找一下。

[root@devops  script]# whereis sudoers
sudoers: /etc/sudoers.d /etc/sudoers /usr/share/man/man5/sudoers.5.gz

sudoers文件默认为只读,增加一下写权限。

[root@devops  script]# ls -l /etc/sudoers 
-r--r-----. 1 root root 4350 Apr 13 08:32 /etc/sudoers
[root@devops  script]# chmod  u+w /etc/sudoers # 修改文件权限为可编辑

修改文件,在如下位置增加一行,保存退出。

[root@devops  script]# vim /etc/sudoers 
...
# 大约在99行附近
99 ## Allow root to run any commands anywhere 
100 root    ALL=(ALL)       ALL
101 devops  ALL=(ALL)       ALL   # 增加此行,devops是你需要授权sudo的用户名
102 
103 ## Allows members of the 'sys' group to run networking, software, 

还原文件权限为只读。

[root@devops  script]# chmod u-w /etc/sudoers 
文章目录