当前位置:网站首页>命令-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
边栏推荐
- SSDB foundation 1
- 剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
- Problems caused by flutter initialroute and home
- SSDB基础
- Some ideas about time-consuming needs assessment
- mysql_linux版本的下載及安裝詳解
- Accessing private members using templates
- The difference between ordinary inner class and static inner class
- Zlib realizes streaming decompression
- First experience of using fluent canvas
猜你喜欢

The fifth bullet of MySQL learning -- detailed explanation of transaction and its operation characteristics

Installation, use and problem summary of binlog2sql tool

Class loading process of JVM

RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`

開關電源設計分享及電源設計技巧圖解

8266 obtain 18b20 temperature

Raspberry pie uses root operation, and the graphical interface uses its own file manager

Getting started with vcpkg

Simplified path (force buckle 71)

First experience of using fluent canvas
随机推荐
Thoughts on the optimization of examination papers in the examination system
Oracle configuration st_ geometry
该买什么设备,Keysight 给你挑好了
Using 8266 as serial port debugging tool
Sogou cell thesaurus analysis (only extract words and word frequency)
openlayers 5.0 两种居中方式
Application of DCT transform
MySQL Téléchargement et installation de la version Linux
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
Client interns of a large factory share their experience face to face
数据分析学习目录
[play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
An example of using JNI to directly access surface data
ArcMap connecting ArcGIS Server
One stop service platform for high-level talents and development of comprehensive service platform system for talents
The difference between ordinary inner class and static inner class
2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
Screen right-click menu in souI
ArcGIS JS API dojoconfig configuration
[报告] Microsoft :Application of deep learning methods in speech enhancement