给用户添加sudo权限

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`
posted @   大道至简,各有其道。  阅读(2897)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示