https://www.cnblogs.com/leoshi/p/12432525.html
Linux系统安全
- 我们一般不会使用root账户去操作我们系统,root在Linux中有至高无上的权利
- 我们一般会开通一个普通用户的权限并赋予sudo的权限
- 普通用户在操作系统时可临时提权
创建普通用户
# 创建用户 useradd -m -s /bin/bash dbuser # 修改密码 passwd dbuser Changing password for user dbuser. New password: Retype new password: passwd: all authentication tokens updated successfully. # 直接修改密码脚本 echo <password> | sudo passwd <username> --stdin &>/dev/null echo 12345678 | passwd dbuser --stdin
方法一: 添加用户至wheel组,CentOS里面wheel具有sudo权限
# usermod -G wheel dbuser
切换到该用户
# su -l dbuser [dbuser@cheery-boots-1 ~]$
方法二(推荐): 修改/etc/sudoers
① 使用root用户登录系统,首先修改文件/etc/sudoers的写权限(默认为只读,增加写的权限)
`chmod 640 /etc/sudoers`
② 使用vim编辑文件/etc/sudoers
`vim /etc/sudoers`
③ 在root后面增加用户名和ALL
`## Allow root to run any commands anywhere root ALL=(ALL) ALL test01 ALL=(ALL) ALL `
④ wq保存,并将/etc/sudoers改为只读
`chmod 440 /etc/sudoers`