首页 技术 正文
技术 2022年11月15日
0 收藏 336 点赞 2,542 浏览 885 个字

CentOS下添加用户并且让用户获得root权限 http://www.centoscn.com/CentOS/config/2014/0810/3471.html

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帐号的权限。

 友情提醒:虽然方法三看上去简单方便,但一般不推荐使用,推荐使用方法二。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,032
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,862