当前位置:网站首页>命令-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
边栏推荐
- Reflection on the performance of some OpenGL operations in the past
- js获取本机ip地址
- Coordinate conversion WGS-84 to gcj-02 and gcj-02 to WGS-84
- 2022.04.23(LC_714_买卖股票的最佳时机含手续费)
- Using oes texture + glsurfaceview + JNI to realize player picture processing based on OpenGL es
- Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
- Openlayers 5.0 reload the map when the map container size changes
- Client interns of a large factory share their experience face to face
- [record] typeerror: this getOptions is not a function
- The platinum library cannot search the debug process records of some projection devices
猜你喜欢
Raspberry pie 18b20 temperature
MySQL Téléchargement et installation de la version Linux
[report] Microsoft: application of deep learning methods in speech enhancement
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
浅谈c语言指针的强制转换
该买什么设备,Keysight 给你挑好了
为何PostgreSQL即将超越SQL Server?
Getting started with vcpkg
Using Visual Studio code to develop Arduino
随机推荐
arcMap 发布切片服务
openlayers 5.0 当地图容器大小改变时,重新加载地图
该买什么设备,Keysight 给你挑好了
Common processing of point cloud dataset
Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique
Coordinate conversion WGS-84 to gcj-02 and gcj-02 to WGS-84
Raspberry pie uses root operation, and the graphical interface uses its own file manager
Wechat applet part of the mobile phone Preview PDF did not respond
Intuitive understanding of the essence of two-dimensional rotation
Why is PostgreSQL about to surpass SQL Server?
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
SQL常用的命令
js 计算时间差
Client interns of a large factory share their experience face to face
为何PostgreSQL即将超越SQL Server?
Sogou cell thesaurus analysis (only extract words and word frequency)
c1000k TCP 连接上限测试
[报告] Microsoft :Application of deep learning methods in speech enhancement
Minesweeping II of souI instance
Some ideas about time-consuming needs assessment