Centos 下安装 添加用户
2015-06-12 13:32
603 查看
查看在线用户:http://blog.csdn.net/lwfcgz/article/details/8115684
新建用户 转:http://www.2cto.com/os/201112/113227.html
测试环境:CentOS 5.5
1、添加用户,首先用adduser命令添加一个普通用户,命令如下:
#adduser tommy
//添加一个名为tommy的用户
#passwd tommy //修改密码
Changing password for user tommy.
New UNIX password: //在这里输入新密码
Retype new UNIX password: //再次输入新密码
passwd: all authentication tokens updated successfully.
2、赋予root权限
方法一: 修改/etc/sudoers 文件,找到下面一行,把前面的注释(#)去掉
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
然后修改用户,使其属于root组(wheel),命令如下:
#usermod -g root tommy
修改完毕,现在可以用tommy帐号登录,然后用命令su – ,即可获得root权限进行操作。
方法二: 修改/etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
tommy ALL=(ALL) ALL
修改完毕,现在可以用tommy帐号登录,然后用命令su – ,即可获得root权限进行操作。
方法三: 修改/etc/passwd 文件,找到如下行,把用户ID修改为0 ,如下所示:
tommy:x:500:500:tommy:/home/tommy:/bin/bash
修改后如下
tommy:x:0:500:tommy:/home/tommy:/bin/bash
保存,用tommy账户登录后,直接获取的就是root帐号的权限。
友情提醒:虽然方法三看上去简单方便,但一般不推荐使用,推荐使用方法二。
作者 yangtao
遇到问题: 在 vi/etc/sudoers文件时 提示此文件为只读文件,明明是用root用户登的缺提示没有权限查资料解决方案:
http://blog.csdn.net/chtdsl/article/details/8879660
输入i,对文件进行编辑,发现底部有只读提示:
-- INSERT -- W10: Warning: Changing a readonly file
应该是没有权限,退出编辑状态后查看权限:
[root@dbs aaa]# ll /etc/sudoers
-r--r-----. 1 root root 3825 Jul 22 01:05 /etc/sudoers
原来root也只有只读权限,难怪,首先修改权限以让root有完全控制权限:
[root@dbs aaa]#chmod 740 /etc/sudoers
再次编辑,这次没有出现只读提示了,找到如下字段:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
Oracle ALL=(ALL) ALL
aaa ALL=(ALL) ALL
添加aaa用户,添加后如aaa ALL=(ALL) ALL
修改完后输入:wq保存,保存后记得把权限修改回去,否则会有错误提示
#chmod 440 /etc/sudoers
权限一定是440,否则就会有错误提示。
OK,在aaa用户下就可以正常使用sudo命令咯。
新建用户 转:http://www.2cto.com/os/201112/113227.html
测试环境:CentOS 5.5
1、添加用户,首先用adduser命令添加一个普通用户,命令如下:
#adduser tommy
//添加一个名为tommy的用户
#passwd tommy //修改密码
Changing password for user tommy.
New UNIX password: //在这里输入新密码
Retype new UNIX password: //再次输入新密码
passwd: all authentication tokens updated successfully.
2、赋予root权限
方法一: 修改/etc/sudoers 文件,找到下面一行,把前面的注释(#)去掉
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
然后修改用户,使其属于root组(wheel),命令如下:
#usermod -g root tommy
修改完毕,现在可以用tommy帐号登录,然后用命令su – ,即可获得root权限进行操作。
方法二: 修改/etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
tommy ALL=(ALL) ALL
修改完毕,现在可以用tommy帐号登录,然后用命令su – ,即可获得root权限进行操作。
方法三: 修改/etc/passwd 文件,找到如下行,把用户ID修改为0 ,如下所示:
tommy:x:500:500:tommy:/home/tommy:/bin/bash
修改后如下
tommy:x:0:500:tommy:/home/tommy:/bin/bash
保存,用tommy账户登录后,直接获取的就是root帐号的权限。
友情提醒:虽然方法三看上去简单方便,但一般不推荐使用,推荐使用方法二。
作者 yangtao
遇到问题: 在 vi/etc/sudoers文件时 提示此文件为只读文件,明明是用root用户登的缺提示没有权限查资料解决方案:
http://blog.csdn.net/chtdsl/article/details/8879660
输入i,对文件进行编辑,发现底部有只读提示:
-- INSERT -- W10: Warning: Changing a readonly file
应该是没有权限,退出编辑状态后查看权限:
[root@dbs aaa]# ll /etc/sudoers
-r--r-----. 1 root root 3825 Jul 22 01:05 /etc/sudoers
原来root也只有只读权限,难怪,首先修改权限以让root有完全控制权限:
[root@dbs aaa]#chmod 740 /etc/sudoers
再次编辑,这次没有出现只读提示了,找到如下字段:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
Oracle ALL=(ALL) ALL
aaa ALL=(ALL) ALL
添加aaa用户,添加后如aaa ALL=(ALL) ALL
修改完后输入:wq保存,保存后记得把权限修改回去,否则会有错误提示
#chmod 440 /etc/sudoers
权限一定是440,否则就会有错误提示。
OK,在aaa用户下就可以正常使用sudo命令咯。
相关文章推荐
- linux下修改IP信息
- linux 好用的程序
- [工作笔记]一个ubuntu配置双网卡双网段IP走不同网关的脚本
- DNS服务器的搭建
- Linux netstat +awk 看攻击IP
- Ubuntu 14.04 LTS 下使用校园网客户端DrclientLinux
- Linux3.10内核之后proc文件系统的使用
- linux(debain)下mysql的密码忘记后的重置方法
- CentOS安装crontab及使用方法(转)
- Linux下autoconf和automake使用转载
- java 使用jsch.jar包通过sftp访问Linux服务器
- Linux下使用ab测试webservice性能
- linux命令2--chgrp命令
- Mesosphere Cluster on CentOS7 (zookeeper+mesos+marathon)
- Linux driver 板级文件跟踪一般方法
- sed截取连接数升高时的慢日志
- linux命令1——chown命令
- vbox宿主机连接虚拟机,linux连接外网配置
- linux命令-windows和linux互传文件
- linux单用户模式