centos新建用户并授权
买了一台阿里云服务器,准备用来做服务使用,但是由于只有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
这样就配好了用户,由于是个人使用,就不配置用户组了
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· winform 绘制太阳,地球,月球 运作规律
· 上周热点回顾(3.3-3.9)