Centos 7 学习之添加用户

本文介绍在 CentOS 系统中如何使用 useradd 命令创建新用户,并通过修改 /etc/sudoers 文件来授予用户 sudo 权限的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.youkuaiyun.com/johnnycode/article/details/40655857

在使用 Centos 之前用的更多是Ubuntu,所以在 useradd 和 adduser 两条命令出现歧义,在Ubuntu系统上这是两条命令,而在Centos上则是同一条命令,adduser 是链接的形式存在

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. # ll /usr/sbin/ | grep user  
  2. lrwxrwxrwx. 1 root root           7 10月 30 17:09 adduser -> useradd  
  3. -rwxr-x---. 1 root root      114064 6月  10 09:16 useradd  
1、添加用户,Centos 没有任何交互动作!创建用户完毕后,必须修改密码否则无法登陆
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. # useradd dev #创建用户  
  2. # passwd dev #修改密码  
  3. 更改用户 dev 的密码 。  
  4. 新的 密码:  
  5. 重新输入新的 密码:  
  6. passwd:所有的身份验证令牌已经成功更新。  

2、为新建用户添加 sudo 权限,否则啥事都要请教 root 老大不合适,你懂得!

1)sudoers 文件添加可写权限

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. # chmod -v u+w /etc/sudoers  
  2. "/etc/sudoers" 的权限模式保留为0640 (rw-r-----)  
2)在 sudoers 文件添加新用户信息到 ## Allow root to run any commands anywher 下,修改后的效果为
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. ## Allow root to run any commands anywher  
  2. root    ALL=(ALL)       ALL  
  3. dev     ALL=(ALL)       ALL #新增用户信息  

3)取消 sudoers 文件可写权限

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. # chmod -v u-w /etc/sudoers  
  2. mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值