当前位置:网站首页>命令-sudo
命令-sudo
2022-04-23 19:19:00 【小怪獣55】
sudo 是一种权限管理机制,它允许系统管理员分配给普通用户一些合理的"权利",让他们执行一些只有超级用户或其他特许用户才能完成的任务,比如:运行一些像mount,halt,su之类的命令,或者编辑一些系统配置文件,像/etc/mtab,/etc /samba/smb.conf等。
1.su
切换用户
格式
#格式
1)su -[l]/--login username
2)su username #不指定username 默认为root
1和2的区别:1切换用户后,同时切换到新用户的工作环境中
2切换用户后,不改变原用户的工作目录,及其他环境变量目录
- 1.
- 2.
- 3.
- 4.
- 5.
范例
[[email protected] ~] # su openstack
[[email protected] root] $ pwd
/root
[[email protected] root] $ exit
exit
[[email protected] ~] # su - openstack
Last login: Sat Apr 23 17:44:35 CST 2022 on pts/0
[[email protected] ~] $ pwd
/home/openstack
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
2.sudo
包:sudo
帮助:man 5 sudoers
作用:授权指定用户,在指定主机上,运行某些命令;如果未授权用户尝试使用sudo,会提示联系管理员
提供日志,记录用户使用sudo操作
为系统管理员提供配置文件,管理用户的使用权限和使用的主机
使用时间戳文件完成类似 "检票"的系统,默认存活期为5min
#通过visudo命令编辑配置文件,具有语法检查功能
用visudo命令编辑 /etc/sudoers
usage: visudo [-chqsV] [-f sudoers]
visudo -c #语法检查
visudo -f /etc/sudoers.d/test
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
2.1.文件
配置文件:/etc/sudoers /etc/sudoers.d/*
时间戳文件:/var/db/sudo
日志文件:/var/log/secure
配置文件支持:通配符glob
?
*
[wxc] #匹配其中一个字符
[!wxc]
\x #转义
[[alpha]]
#配置文件规则有两类:
1.别名定义:不是必须的
2.授权规则:必须
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
2.2.授权规则
user host = (runas) command
用户 登入主机 = (代表用户) 命令
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
root ALL = (ALL) ALL
user: #运行命令者的身份
host: #通过哪些主机
(runas): #以哪个用户的身份
command: #运行哪些命令
#范例:
wang 192.168.37 .7 =(root) /bin/mount /dev/sr0 /mnt
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
2.3.别名
#user和runas:
username
#uid
%group_name
% #gid
user_alias|runas_alias
#host:
ip或hostname
network(/netmask)
host_alias
#command:
command name
directory
sudoedit
Cmnd_Alias
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#别名四种类型
User_Alias
Runas_Alias
Host_Alias
Cmnd_Alias
#别名格式
[A-Z]([A-Z][0-9]_)*
#别名定义:
Alias_Type NAME1 =item1,item2,item3 :NAME2 =item4,item5
范例1:
Student ALL =(ALL) ALL
%wheel ALL =(ALL) ALL
范例2:
Student ALL =(root) /sbin/pidof,/sbin/ifconfig
%wheel ALL =(ALL) NOPASSWD:ALL
范例3:
User_Alias NETADMIN = netuser1,netuser2
Cmnd_Alias NETCMD = /usr/sbin/ip
NETADMIN ALL =(root) NETCMD
范例4:
User_Alias SYSADER =wang,mage,%admins
User_Alias DISKADER =tom
Host_Alias SERS =www.magedu.com,172.16.0.0/24
Runas_Alias OP =root
Cmnd_Alias SYDCMD =/bin/chown,/bin/chmod
Cmnd_Alias DSKCMD =/sbin/parted,/sbin/fdisk
SYSADER SERS = SYDCMD,DSKCMD
DISKADER ALL =(OP) DSKCMD
User_Alias ADMINUSER = adminuser1,adminuser2
Cmnd_Alias ADMINCMD = /usr/sbin/useradd,/usr/sbin/usermod, /usr/bin/passwd [a-zA-Z]*, !/usr/bin/passwd root
ADMINUSER ALL =(root) NOPASSWD:ADMINCMD,PASSWD:/usr/sbin/userdel
范例5:
Defaults:wang runas_default =tom
wang ALL =(tom,jerry) ALL
范例6:
wang 192.168.1.6,192.168.1 .8 =(root) /usr/sbin/,!/usr/sbin/useradd
范例7:
wang ALL =(ALL) /bin/cat /var/log/messages*
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
2.4.sudo命令
sudo –i –u wang 切换身份
sudo [-u user] COMMAND
-V #示版本信息等配置信息
-u user #认为root
-l,ll #列出用户在主机上可用的和被禁止的命令
-v #再延长密码有效期限5分钟,更新时间戳
-k #清除时间戳(1970-01-01),下次需要重新输密码
-K #-k类似,还要删除时间戳文件
-b #后台执行指令
-p #改变询问密码的提示符号
示例:-p "password on %h for user %p:"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
版权声明
本文为[小怪獣55]所创,转载请带上原文链接,感谢
https://blog.51cto.com/taowenwu/5248723
边栏推荐
- 開關電源設計分享及電源設計技巧圖解
- FTP, SSH Remote Access and control
- Openlayers 5.0 two centering methods
- SQL server requires to query the information of all employees with surname 'Wang'
- ArcMap连接 arcgis server
- Web Security
- One stop service platform for high-level talents and development of comprehensive service platform system for talents
- 8266 obtain 18b20 temperature
- 腾讯云GPU最佳实践-使用jupyter pycharm远程开发训练
- 高层次人才一站式服务平台开发 人才综合服务平台系统
猜你喜欢
Wechat video extraction and receiving file path
8266 obtain 18b20 temperature
【C语言进阶11——字符和字符串函数及其模拟实现(2))】
Switching power supply design sharing and power supply design skills diagram
binlog2sql 工具安装使用及问题汇总
On the forced conversion of C language pointer
Android Development: the client obtains the latest value in the database in real time and displays it on the interface
mysql_linux版本的下载及安装详解
2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
随机推荐
Common processing of point cloud dataset
JS controls the file type and size when uploading files
HTTP cache - HTTP authoritative guide Chapter VII
How about CICC wealth? Is it safe to open an account up there
高层次人才一站式服务平台开发 人才综合服务平台系统
On the forced conversion of C language pointer
Is it safe to open an account in Bohai futures.
JS to get the local IP address
openlayers 5.0 当地图容器大小改变时,重新加载地图
Openlayers 5.0 discrete aggregation points
Wechat video extraction and receiving file path
Zlib realizes streaming decompression
Openlayers draw rectangle
数据分析学习目录
SQL of contention for system time plus time in ocrale database
@Analysis of conditional on Web Application
ArcMap连接 arcgis server
Wechat applet part of the mobile phone Preview PDF did not respond
JVM的类加载过程
剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)