sudo命令用于给普通用户提供额外权利来完成原本只有超级用户才有权限完成的任务,

格式:sudo [参数] 命令名称

sudo命令与su命令的区别是,su命令允许普通用户完全变更为超级管理员的身份,但

如此一来便增加了安全隐患,而使用sudo命令可以仅将特定的命令/程序执行权限赋予

指定的用户。

sudo命令的特色:

:限制用户执行指定的命令
:记录用户执行的每一条命令
:验证过密码后5分钟(默认值)内无需再让用户验证密码,更加方便。

sudo程序的配置文件为/etc/sudoers,只有超级用户可以使用visudo编辑该文件。

实例1:使用visudo命令编辑sudo程序的配置文件,在第99行添加参数允许pentest用户

能够从任意主机执行任意命令的参数。

       ## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## users or groups.
##
## This file must be edited with the 'visudo' command. ## Host Aliases
## Groups of machines. You may prefer to use hostnames (perhaps using
## wildcards for entire domains) or IP addresses instead.
# Host_Alias FILESERVERS = fs1, fs2
# Host_Alias MAILSERVERS = smtp, smtp2 ## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS
# User_Alias ADMINS = jsmith, mikem ## Command Aliases
## These are groups of related commands... ## Networking
# Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool ## Installation and management of software
# Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum ## Services
# Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig, /usr/bin/systemctl start, /usr/bin/systemctl stop, /usr/bin/systemctl reload, /usr/bin/systemctl restart, /usr/bin/systemctl status, /usr/bin/systemctl enable, /usr/bin/systemctl disable ## Updating the locate database
# Cmnd_Alias LOCATE = /usr/bin/updatedb ## Storage
# Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount ## Delegating permissions
# Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp ## Processes
# Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall ## Drivers
# Cmnd_Alias DRIVERS = /sbin/modprobe # Defaults specification #
# Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
# You have to run "ssh -t hostname sudo <cmd>".
#
Defaults requiretty #
# Refuse to run if unable to disable echo on the tty. This setting should also be
# changed in order to be able to use sudo without a tty. See requiretty above.
#
Defaults !visiblepw #
# Preserving HOME has security implications since many programs
# use it when searching for configuration files. Note that HOME
# is already set when the the env_reset option is enabled, so
# this option is only effective for configurations where either
# env_reset is disabled or HOME is present in the env_keep list.
#
Defaults always_set_home Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"
Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY" #
# Adding HOME to env_keep may enable a user to run unrestricted
# commands via sudo.
#
# Defaults env_keep += "HOME" Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin ## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
pentest ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS ## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL ## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL ## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom ## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
[root@localhost ~]#

切换到pentest用户查看可以执行的命令,提示为ALL,即可以执行所有超级管理员的命令。

[root@localhost ~]# su - pentest
上一次登录:五 9月 :: CST 2016pts/ 上
[pentest@localhost ~]$ sudo -l
[sudo] password for pentest:
匹配此主机上 pentest 的默认条目:
requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME
HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS
LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES",
env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL
LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin 用户 pentest 可以在该主机上运行以下命令:
(ALL) ALL

使用普通ls命令来查看/root文件夹出现“权限不够”,然后使用sudo ls后便可以查看了。

[pentest@localhost ~]$ ls /root/
ls: 无法打开目录/root/: 权限不够
[pentest@localhost ~]$ sudo ls /root/
[sudo] password for pentest:
anaconda-ks.cfg testA testC 公共 视频 文档 音乐
initial-setup-ks.cfg testB yum 模板 图片 下载 桌面
[pentest@localhost ~]$

实例2:仅允许pentest以root身份执行cat命令

pentest用户先以普通权限cat文件/etc/shadow发现权限不够
[pentest@localhost ~]$ cat /etc/shadow
cat: /etc/shadow: 权限不够 切换至root用户给予pentest用户cat权限
[pentest@localhost ~]$ su - root
密码:
上一次登录:五 9月 :: CST 2016pts/ 上
[root@localhost ~]# visudo
[root@localhost ~]# su - pentest
上一次登录:五 9月 :: CST 2016pts/1、 上 赋予执行cat权限
[root@localhost ~]# visudo
root    ALL=(ALL)       ALL
pentest ALL=(root)      /bin/cat 继续使用普通cat确认是否可以查看/etc/shadow提示权限不够
[pentest@localhost ~]$ cat /etc/shadow
cat: /etc/shadow: 权限不够 使用sudo cat查看/etc/shadow发现可以查看了。
[pentest@localhost ~]$ sudo cat /etc/shadow
root:$$Y6LHG5EEAGs3JMUM$jcEE.RZgMF9mO/xiPVA522l1Ek8JZ2Nkl.9nCBuiUWAH/.F84Kj6XyNxbuecW1M4BNGpryB/10Ncp.EGu9VhZ/:::::::
bin:*:::::::
daemon:*:::::::
adm:*:::::::
lp:*:::::::
sync:*:::::::
shutdown:*:::::::
halt:*:::::::
mail:*:::::::
operator:*:::::::
games:*:::::::
ftp:*:::::::
nobody:*:::::::
avahi-autoipd:!!:::::::
ods:!!:::::::
pegasus:!!:::::::
systemd-bus-proxy:!!:::::::
systemd-network:!!:::::::
dbus:!!:::::::
polkitd:!!:::::::
sssd:!!:::::::
colord:!!:::::::
apache:!!:::::::
tss:!!:::::::
unbound:!!:::::::
usbmuxd:!!:::::::
abrt:!!:::::::
amandabackup:!!:::::::
saslauth:!!:::::::
libstoragemgmt:!!:::::::
geoclue:!!:::::::
memcached:!!:::::::
rpc:!!:::::::
postfix:!!:::::::
setroubleshoot:!!:::::::
rtkit:!!:::::::
chrony:!!:::::::
mysql:!!:::::::
qemu:!!:::::::
ntp:!!:::::::
rpcuser:!!:::::::
nfsnobody:!!:::::::
radvd:!!:::::::
named:!!:::::::
pcp:!!:::::::
pulse:!!:::::::
hsqldb:!!:::::::
tomcat:!!:::::::
pkiuser:!!:::::::
gdm:!!:::::::
gnome-initial-setup:!!:::::::
avahi:!!:::::::
postgres:!!:::::::
dovecot:!!:::::::
dovenull:!!:::::::
sshd:!!:::::::
oprofile:!!:::::::
tcpdump:!!:::::::
pentest:$$6U3Z2n.sd63M32ZS$tzQJg852/1G3Mw7uv1.Ipbh.lOusvfd47Ih52xxku7okBBb/nu.Vn5V4mB50SSCMfaspqeGSDLcPM7XdgLE2w/:::::::
[pentest@localhost ~]$

Linux命令-sudo的更多相关文章

  1. linux命令-sudo普通用户拥有root权限

    普通用户权限不够 [root@wangshaojun ~]# su - dennywang[dennywang@wangshaojun ~]$ ls /root/ls: 无法打开目录/root/: 权 ...

  2. Linux 命令 sudo

    sudo 这个命令. 是为了 让 普通用户 ,也能够以root的身份来运行 操作, 而这些普通用户 又不须要知道root的password. 在 sudo 运行命令的时候. 仅仅须要 输入自己的pas ...

  3. (6)sudo命令详解(每周一个linux命令系列)

    首先说句抱歉,最近事情比较复杂,停更了一阵子.我又回来啦 多用户管理 我们常用的windows个人系统虽然可以设置多用户,但是实际上是不可以多用户同时登陆的(这个我实验过,我以前用windows服务器 ...

  4. Linux命令之sudo

    在 Linux  系统中,由于 root 的权限过大,一般情况下都不使用它.只有在一些特殊情况下才采用登录root 执行管理任务,一般情况下临时使用 root 权限多采用 su 和 sudo 命令. ...

  5. Linux学习总结(六)-su命令 sudo 命令 限制root远程登录

    root 用户拥有至高无上的权利,那么我们运维人员是不是直接在root用户下处理所有问题呢? 答案是否定的,权力越大,责任越大,人是会犯错的,因此我们要在不影响我们的工作情况下,尽量限制我们的权力,以 ...

  6. 用大写字母输入 Linux 命令,实现以 sudo 用户权限运行

    我们知道,一些 Linux 命令是要通过 sudo 权限才能运行的,这需要我们每次使用这些命令时在前面加一个 sudo ,十分繁琐.今天给大家介绍一个好用的工具 SUDO ,它只需要我们用大写字母键入 ...

  7. Linux命令——su 、su -、sudo

    前言 大部分Linux发行版的默认账户是普通用户,而更改系统文件或者执行某些命令,需要root身份才能进行,这就需要从当前用户切换到root用户. 切换用户身份有两个命令 su [-] usernam ...

  8. Ubuntu Linux使用sudo命令搭建java环境

    搬运stackoverflow 注意,以下所有命令需要在root权限下执行 1. 在Ubuntu下打开终端命令或用ssh连接到linux. 2. 更新仓库(只有Ubuntu17.4及以下系统可用): ...

  9. Linux下 sudo命令

    平常使用Linux的时候,都是用普通用户登录执行命令,但是有些命令需要root权限才能执行,如果切换到root用户去执行,就需要输入root密码,为了系统的安全性,应该尽可能少的直接在终端上输入roo ...

随机推荐

  1. github -- fork提交项目

    我们在进行Github协同开发的时候,往往会去fork一个仓库到自己的Github中,过一段时间以后,原仓库可能会有各种提交以及修改,很可惜,Github本身并没有自动进行同步的机制,这个需要我们手动 ...

  2. Web前端技能

    入门必备的技能: 第1项技能:HTML超文本标记语言: 技能要点: HTML文件的结构    HTML文件的编写方法     HTML基本标记    文字与段落标记     框架    使用表单    ...

  3. SQL SERVER数据库修改是否区分大小写

    昨天去客户,发现程序无法应用,跟踪错误提示,提示的大致意思是“数据库表名和数据库字段名不存在”.查询后发现是SQL Server数据库设置了区分大小写的缘故(一般安装时,Oracle的正确安装下是默认 ...

  4. android apk 自我保护技术-加密apk

    经过了忙碌的一周终于有时间静下来写点东西了,我们继续介绍android apk防止反编译技术的另一种方法.前两篇我们讲了加壳技术(http://my.oschina.net/u/2323218/blo ...

  5. Jquery方法的应用

    <body> <div id="one"><span>one</span></div><div class=&qu ...

  6. Poj 1904 King's Quest 强连通分量

    题目链接: http://poj.org/problem?id=1904 题意: 有n个王子和n个公主,王子只能娶自己心仪的公主(一个王子可能会有多个心仪的公主),现已给出一个完美匹配,问每个王子都可 ...

  7. Codeforces Round #353 (Div. 2) D. Tree Construction 二叉搜索树

    题目链接: http://codeforces.com/contest/675/problem/D 题意: 给你一系列点,叫你构造二叉搜索树,并且按输入顺序输出除根节点以外的所有节点的父亲. 题解: ...

  8. CKEditor (Toolbar Definition)工具栏自定义配置

    JS是大小写敏感的, 在设置配置文件的时候需要注意 以CKEditor 4为基础我们可以通过两种方式配置CKEditor的工具栏,一种是是通过config.js配置文件设置, 另一种是IN-PAGE方 ...

  9. Python编程指南 chapter 1

    1.python使用方括号[]来存取一个序列中的某个数据项,像字符串.列表等包含若干数据项的序列都采用这种方法. 2.强制类型转换,int('24234'),str(235) 3.python中没有变 ...

  10. nginx js、css多个请求合并为一个请求(concat模块)

    模块介绍 mod_concat模块由淘宝开发,目前已经包含在tengine中,并且淘宝已经在使用这个nginx模块.不过塔暂时没有包含在nginx中.这个模块类似于apache中的modconcat. ...