Linux创建用户并赋予Root权限

添加普通用户

[root@server ~]# useradd test //添加一个名为test的用户
[root@server ~]# passwd test //修改密码
Changing password for user test.
New UNIX password: //在这里输入新密码
Retype new UNIX password: //再次输入新密码
passwd: all authentication tokens updated successfully

赋予root权限

方法一:

修改/etc/sudoers文件,把前面的注释(#)去掉
## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL

然后修改用户,使其属于root组(wheel),命令如下:
[root@server ~]# usermod -g root test
修改完毕,用test帐号登录,然后用命令su –切换,即可获得root权限进行操作。

 

方法二:

修改/etc/sudoers文件,找到下面一行,
## Allow root to run any commands anywhere 
root ALL=(ALL) ALL
在root下面添加一行,如下所示:
test ALL=(ALL) ALL
修改完毕,用test帐号登录,然后用命令su –,即可获得root权限进行操作。

方法三:

修改/etc/passwd文件,找到如下行,把用户ID修改为0,如下所示:
test:x:502:502::/home/test:/bin/bash
修改后保存,用test账户登录后,直接获取的就是root帐号的权限。

 

解决ssh远程登陆linux显示-bash-4.1$

linux系统新建的用户用ssh远程登陆显示-bash-4.1$,不显示用户名路径,这个问题的根本原因就是缺少shell环境。
解决方法就是把/etc/skel/.bash*拷贝到当前用户目录下。

执行如下命令拷贝:
cp -pr /etc/skel/.bash* /home/test/

#/home/test是用户目录

 

解决xxx is not in the sudoers file错误

使用sudo命令切换用户的时候可能会遇到提示以下错误:

xxx is not in the sudoers file. This incident will be reported

xxx是你当前的用户名,出现这样的错误是因为用户没有加入到sudo的配置文件里。

1.切换到root用户,运行visudo命令

2.在打开的配置文件中,找到root ALL=(ALL) ALL,在下面添加一行
xxx ALL=(ALL) ALL 其中xxx是你要加入的用户名称

3.输入:wq保存并退出配置文件,再次使用sudo命令就不会有上面的提示了

 

posted @ 2014-10-12 15:38  邴越  阅读(6207)  评论(0编辑  收藏  举报