visudo 普通用户账户 添加root全新
2013-01-30 11:02
344 查看
http://inotseeyou.com/2011/04/02/etcsudoers/
http://blog.sina.com.cn/s/blog_6ffa25ae01015vz9.html
sudo是linux下常用的允许普通用户使用超级用户权限的工具。
它的主要配置文件是sudoers,linux下通常在/etc目录下,如果是solaris,缺省不装sudo的,编译安装后通常在安装目录的 etc目录下,不过不管sudoers文件在哪儿,sudo都提供了一个编辑该文件的命令:visudo来对该文件进行修改。强烈推荐使用该命令修改 sudoers,因为它会帮你校验文件配置是否正确,如果不正确,在保存退出时就会提示你哪段配置出错的。
言归正传,下面介绍如何配置sudoers
首先写sudoers的缺省配置:
#############################################################
# sudoers file.
#
# This file MUST be edited with the ‘visudo’ command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
# User privilege specification
root ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
##################################################################
1. 最简单的配置,让普通用户support具有root的所有权限
执行visudo之后,可以看见缺省只有一条配置:
root ALL=(ALL) ALL
那么你就在下边再加一条配置:
support ALL=(ALL) ALL
这样,普通用户support就能够执行root权限的所有命令
以support用户登录之后,执行:
sudo su -
然后输入support用户自己的密码,就可以切换成root用户了
2. 让普通用户support只能在某几台服务器上,执行root能执行的某些命令
首先需要配置一些Alias,这样在下面配置权限时,会方便一些,不用写大段大段的配置。Alias主要分成4种
Host_Alias
Cmnd_Alias
User_Alias
Runas_Alias
1) 配置Host_Alias:就是主机的列表
Host_Alias HOST_FLAG = hostname1, hostname2, hostname3
2) 配置Cmnd_Alias:就是允许执行的命令的列表
Cmnd_Alias COMMAND_FLAG = command1, command2, command3
3) 配置User_Alias:就是具有sudo权限的用户的列表
User_Alias USER_FLAG = user1, user2, user3
4) 配置Runas_Alias:就是用户以什么身份执行(例如root,或者oracle)的列表
Runas_Alias RUNAS_FLAG = operator1, operator2, operator3
5) 配置权限
配置权限的格式如下:
USER_FLAG HOST_FLAG=(RUNAS_FLAG) COMMAND_FLAG
如果不需要密码验证的话,则按照这样的格式来配置
USER_FLAG HOST_FLAG=(RUNAS_FLAG) NOPASSWD: COMMAND_FLAG
配置示例:
############################################################################
# sudoers file.
#
# This file MUST be edited with the ‘visudo’ command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
Host_Alias EPG = 192.168.1.1, 192.168.1.2
# User alias specification
# Cmnd alias specification
Cmnd_Alias SQUID = /opt/vtbin/squid_refresh, /sbin/service, /bin/rm
# Defaults specification
# User privilege specification
root ALL=(ALL) ALL
support EPG=(ALL) NOPASSWD: SQUID
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
============
转载▼
*** is not in the sudoers file. This incident will be reported.”
(用户不在sudoers文件中……)
处理这个问题很简单,但应该先理解其原理再操作
首先要明白root的密码一般用户是不应改知道的,但一般用户有时可能要用到root的一些权限。
这里就有了一个 /etc/sudoers 文件,用来保存一些用户,使这些用户可以通过sudo命令来暂时获取root的权限。这些用户使用sudo时输入的密码是当前用户密码,而不是root密码。还可一在sudoers文件里限制一般用户的权限,这样就有了安全保证。
现在要让jack用户获得sudo使用权
1.切换到超级用户root
$su root
2.查看/etc/sudoers权限,可以看到当前权限为440
$ ls -all /etc/sudoers
-r--r----- 1 root root 744 6月 8 10:29 /etc/sudoers
3.更改权限为777
$chmod 777 /etc/sudoers
4.编辑/etc/sudoers
$vi /etc/sudoers
5.在root ALL=(ALL:ALL) ALL 下面添加一行
jack ALL=(ALL)ALL
然后保存退出。
第一个ALL是指网络中的主机,我们后面把它改成了主机名,它指明jack可以在此主机上执行后面的命令。
第二个括号里的ALL是指目标用户,也就是以谁的身份去执行命令。
最后一个ALL当然就是指命令名了。
具体这里不作说明
6.把/etc/sudoers权限改回440
$chmod 440 /etc/sudoers
7.操作完成,切换到jack用户测试一下
本文出自 “企鹅一家亲” 博客,请务必保留此出处http://redhatdebian.blog.51cto.com/1197273/1129602
http://blog.sina.com.cn/s/blog_6ffa25ae01015vz9.html
sudo是linux下常用的允许普通用户使用超级用户权限的工具。
它的主要配置文件是sudoers,linux下通常在/etc目录下,如果是solaris,缺省不装sudo的,编译安装后通常在安装目录的 etc目录下,不过不管sudoers文件在哪儿,sudo都提供了一个编辑该文件的命令:visudo来对该文件进行修改。强烈推荐使用该命令修改 sudoers,因为它会帮你校验文件配置是否正确,如果不正确,在保存退出时就会提示你哪段配置出错的。
言归正传,下面介绍如何配置sudoers
首先写sudoers的缺省配置:
#############################################################
# sudoers file.
#
# This file MUST be edited with the ‘visudo’ command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
# User privilege specification
root ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
##################################################################
1. 最简单的配置,让普通用户support具有root的所有权限
执行visudo之后,可以看见缺省只有一条配置:
root ALL=(ALL) ALL
那么你就在下边再加一条配置:
support ALL=(ALL) ALL
这样,普通用户support就能够执行root权限的所有命令
以support用户登录之后,执行:
sudo su -
然后输入support用户自己的密码,就可以切换成root用户了
2. 让普通用户support只能在某几台服务器上,执行root能执行的某些命令
首先需要配置一些Alias,这样在下面配置权限时,会方便一些,不用写大段大段的配置。Alias主要分成4种
Host_Alias
Cmnd_Alias
User_Alias
Runas_Alias
1) 配置Host_Alias:就是主机的列表
Host_Alias HOST_FLAG = hostname1, hostname2, hostname3
2) 配置Cmnd_Alias:就是允许执行的命令的列表
Cmnd_Alias COMMAND_FLAG = command1, command2, command3
3) 配置User_Alias:就是具有sudo权限的用户的列表
User_Alias USER_FLAG = user1, user2, user3
4) 配置Runas_Alias:就是用户以什么身份执行(例如root,或者oracle)的列表
Runas_Alias RUNAS_FLAG = operator1, operator2, operator3
5) 配置权限
配置权限的格式如下:
USER_FLAG HOST_FLAG=(RUNAS_FLAG) COMMAND_FLAG
如果不需要密码验证的话,则按照这样的格式来配置
USER_FLAG HOST_FLAG=(RUNAS_FLAG) NOPASSWD: COMMAND_FLAG
配置示例:
############################################################################
# sudoers file.
#
# This file MUST be edited with the ‘visudo’ command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
Host_Alias EPG = 192.168.1.1, 192.168.1.2
# User alias specification
# Cmnd alias specification
Cmnd_Alias SQUID = /opt/vtbin/squid_refresh, /sbin/service, /bin/rm
# Defaults specification
# User privilege specification
root ALL=(ALL) ALL
support EPG=(ALL) NOPASSWD: SQUID
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
============
添加用户到sudoers
(2012-06-08 10:34:13)转载▼
标签:sudosudoersit | 分类: 技术篇_Linux |
(用户不在sudoers文件中……)
处理这个问题很简单,但应该先理解其原理再操作
首先要明白root的密码一般用户是不应改知道的,但一般用户有时可能要用到root的一些权限。
这里就有了一个 /etc/sudoers 文件,用来保存一些用户,使这些用户可以通过sudo命令来暂时获取root的权限。这些用户使用sudo时输入的密码是当前用户密码,而不是root密码。还可一在sudoers文件里限制一般用户的权限,这样就有了安全保证。
现在要让jack用户获得sudo使用权
1.切换到超级用户root
$su root
2.查看/etc/sudoers权限,可以看到当前权限为440
$ ls -all /etc/sudoers
-r--r----- 1 root root 744 6月 8 10:29 /etc/sudoers
3.更改权限为777
$chmod 777 /etc/sudoers
4.编辑/etc/sudoers
$vi /etc/sudoers
5.在root ALL=(ALL:ALL) ALL 下面添加一行
jack ALL=(ALL)ALL
然后保存退出。
第一个ALL是指网络中的主机,我们后面把它改成了主机名,它指明jack可以在此主机上执行后面的命令。
第二个括号里的ALL是指目标用户,也就是以谁的身份去执行命令。
最后一个ALL当然就是指命令名了。
具体这里不作说明
6.把/etc/sudoers权限改回440
$chmod 440 /etc/sudoers
7.操作完成,切换到jack用户测试一下
本文出自 “企鹅一家亲” 博客,请务必保留此出处http://redhatdebian.blog.51cto.com/1197273/1129602
相关文章推荐
- linux中给普通用户添加root用户权限
- centos添加普通用户禁止root登录并添加sudo权限
- centos7 创建普通用户,添加sudo权限,禁止root远程登录和公钥登录脚本
- Rhel 7.4 普通用户下切换到root账户
- linux限制用户登录(ROOT及普通账户),禁止ping
- kali添加普通用户以及从root切换到普通用户
- linux 如何在root 用户和普通账户间切换
- Fedora 12 普通用户的自动登录 root账户登陆x界面
- cygwin模拟器默认普通用户转为root(#)用户。
- FreeBSD从普通用户切换到root用户
- CentOS6.6普通用户使用sudo命令借用root用户权限
- Linux 禁止普通用户su切换root
- ubuntu在登录界面添加root用户登录的办法
- 添加用户-查看用户列表-禁止默认root登陆
- ubuntu下root用户和普通用户的切换命令
- 普通用户免密码切换到root
- Linux 从普通用户切换到root,两种方式的区别
- 普通用户提权root的尝试
- linux 普通用户 root用户无法使用第三方工具正常登录
- Linux:让普通用户临时性获得root用户权限