您的位置:首页 > 其它

创建Ubuntu用户以及让新用户增加sudo权限

2013-12-26 12:47 337 查看


用户管理


增加用户

sudo adduser 用户名



删除用户

sudo deluser 用户名



修改当前用户的密码 

passwd



修改用户密码 

sudo passwd 用户名



修改用户资料

sudo chfn userid



如何禁用/启用某个帐户

sudo usermod -L 用户名 #锁定用户
sudo usermod -U 用户名 #解锁
或
sudo passwd -l 用户名 #锁定用户
sudo passwd -u 用户名 #解锁



增加用户到admin组,让其有sudo权限

sudo usermod -G admin -a 用户名



如何切换到其他帐号(需要该用户的密码)

su 用户名



如何切换到root帐号

sudo -s
sudo -i
sudo su



一、创建新用户(完整)

sunny@sunny-Lenovo:~$ sudo adduser haha //创建新用户haha
[sudo] password for sunny:
Adding user `haha' ...
Adding new group `haha' (1004) ...
Adding new user `haha' (1002) with group `haha' ..
Creating home directory `/home/haha' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: //输入新用户的密码
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for haha
Enter the new value, or press ENTER for the default
Full Name []: cysys1  //输入新用户的全称
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
到了这一步,新用户已经添加成功了,此时我们可以打 ls /home查看一下,如果显示 username ,侧代表用户创建成功。


二、删除用户:
sodu userdel haha //删除haha用户


三、赋予新用户sudo权限

1、sudo vim /etc/sudoers 或者 sudo visudo

2、在最后一行加上: 用户名   ALL=(ALL:ALL) ALL

例如 : haha  ALL=(ALL:ALL) ALL

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults	env_reset
Defaults	mail_badpass
Defaults	secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root	ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo	ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

haha ALL=(ALL:ALL) ALL

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