您的位置:首页 > 运维架构 > Linux

在centos 中添加一个新用户,并授权

2017-02-25 13:19 330 查看
初步进入centos学习,配置用户

1,创建用户

创建用户 advisen

[root@centos etc]# useradd advsien
[root@centos etc]#


2,创建密码
[root@centos etc]# useradd advisen
[root@centos etc]# passwd advisen
更改用户 advisen 的密码 。
新的 密码:
重新输入新的 密码:
抱歉,密码不匹配。
新的 密码:
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
[root@centos etc]#


3,用户授权

创建账户必须授权,不然,个人用户的权限只可以在本home下有权限,其他的必须有授权,一般需要root的权限

sudo的命令授权一般在sudoers里面

找到sudoer文件位置

看下文件的权限

[root@centos etc]# sudoers
-bash: sudoers: command not found
[root@centos etc]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz
[root@centos etc]#


只读的文件,可以修改权限或者强行保存

[root@centos etc]# vi /etc/sudoers



## Allow root to run any commands anywher
root    ALL=(ALL)       ALL
advisen  ALL=(ALL)       ALL  #这个是新增的用户



用x!命令强制保存


或者修改文件权限

chmod -v u+w /etc/sudoers


配置完了,最好把权限收回

chmod -v u-w /etc/sudoers


到这里基本结束了,

可以用新用户登陆了,使用sudo命令这块

login as: advisen
advisen@192.168.204.129's password:
[advisen@centos ~]$ sudo cat /etc/passwd

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 advisen:


到这里应该是添加成功了,但是,郁闷的是,但是好像出了点小问题,待查

[advisen@centos ~]$ yum install -y vim
Loaded plugins: fastestmirror, refresh-packagekit
You need to be root to perform this command.
[advisen@centos ~]$

解决如下,敬请指导

用su root 命令获取root权限,完成
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: