给用户添加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`
标签:
sudo
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?