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

这样就配好了用户,由于是个人使用,就不配置用户组了

posted @   聚乙烯  阅读(207)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· winform 绘制太阳,地球,月球 运作规律
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示