首页 > 编程知识 正文

sudo -i命令,sudo password for

时间:2023-05-04 11:48:00 阅读:27242 作者:3345

今天的内容: 1、高级权限setfacl2、sudosusudo http://www.Sina.com/http://www.Sina.com /

PS:chmod命令可以将权限分为三组: u、g和o,但setfacl可以为每个文件和目录设置更准确的文件权限。一、高级权限setfacl对于需要特殊权限的使用情况非常有用。

[root@peng ~]# getfacl 1.txt #用户、组和其他人对文件的权限# file :1.txt # owner : root # group : root user :3360 rw-group :3360 r-- other :3360 r--通常清空other权限,然后在setfacl中逐个管理umask以创建新文件只看umask和用户就可以了。 setfacl -m o:-分位和运算:两者结果相同则相同,不同则筛掉,以确保安全为前提。 用户对沿途路径具有x权限,在这种情况下为只读且不可写入; [ root @ Peng~] # setfacl-mm :3360 r1. txt [ root @ Peng~] # getfacl1. txt # file 33601.txt # owner 3360 root # group : root user :3360 rw-- user : egon 013: rw-- # effective : r-- group :3360 r-- mask 33:360 r-# # 显示other :---[ root @ Peng~] # su-egon 01-c ' echo 123/root/1.txt '-bash :/root/1.txt ] 之后只需控制用户或组的权限即可,掩码值会相应变动;

权限优先级(查看单个配置权限,然后查看默认配置权限选项示例) setfacl-MD : u : RWA.txt setfacl-MD 3360 g : RWA.txt-m #所有者或所属组或其他用户在通过更改为组设置权限后续选项d #的目录下的子文件中,单击, 该目录的权限更改所有者的权限setfacl -m u:权限a.txt更改所有者组的权限setfacl -m g:权限a.txt更改其他人的权限setfacl -m o:权限a.txt 60:权限a.txt修改u:用户名3360权限a.txt特定组的权限setfacl -m g:组名3360权限a.txt应用场景练习问题:

概念:可以更精确的控制权限的分配

1、其他人对文件没有任何权限,并单独设置其他人中的egon01对文件夹有r权限, egon02对文件具有w权限setfacl-mo :3360-1.txt setfacl-mu : egon 0133603360 r1. txt setfacl-mu : egon 0233603360 w1. txt egon02单独安装对文件具有w权限的setfacl-mo :3360 rw1. txt setfacl-mu : egon 0133603360 r1. txt setfacl-mu 3360 egon 000

2、查看、更改文件属性

1lsattr #用于显示文件属性格式的lsattr 1.txt2chattr #用于更改文件属性选项的a #仅允许附加内容允许i #禁止更改#不更改常规a #访问时间的示例: [ . txt lattr/opt------------------------ opt-----------1.txt---------- 1

二. su和sudo 可针对单一用户、单一文件、单一目录来进行r,w,x的权限控制

建议使用PS:su -在su和su之间切换的最大本质区别是,su :即以非登录方式切换了根,但shell环境仍然正常使用

户的Shell;su -:即登录式,则连用户和Shell环境一起切换成root身份了;只有切换了Shell环境才不会出现PATH环境变量错误!

1、切换登录级别方式 1>登录式shell**

输入账号密码登录su - egon #登录式shell登录式shell优先级:/etc/profile--->/etc/profile.d/*.sh--->~/.bash_profile--->~/.bashrc--->/etc/bashrc1>输入账号密码登录进来;2>管理员root切换到普通用户下无需密码,反之需要

2>非登录式shell

登录式shell优先级:~/.bashrc---->/etc/bashrc----->/etc/profile.d/*.shsu egon #非登录式shellexprofile #vim编辑完在末行添加,环境变量全局生效

如果想针对所有用户以及登录与非登录shell设置统一的配置-,则编辑/etc/bashrc文:

[root@web01 ~]# vim /etc/bashrc [root@web01 ~]# source /etc/bashrc # 当前环境让该文件生效(或重启也可生效)PS:/etc/profile------------->此配置文件为:更改登录级别的所有用户

 

ifconfig ens33:0 1.1.1.1 制作一块虚拟网卡

 

二、sudo提权

概念:sudo是在普通用户身份不变的情况下,可以执行root管理员的部分权限,而不需知道root管理员的密码,起到提权的作用。

格式sudo cat /root/1.txtsudo  -k 清除缓存密码,再登录时需再输密码

配置的两种方式:

方式1>visudo

在管理员下修改配置文件/etc/sudoers来分配权限vim /etc/sudoers  # 风险高visudo -c # 修改完后检查语法是否有错误,visudo -c回车,不需要加文件路径

方式2>vim /etc/sudoers

[root@test ~]# cat /etc/sudoers## Sudoers allows particular users to run various commands as## the root user, without needing the root password.该文件允许特定用户像root用户一样使用各种各样的命令,而不需要root用户的密码​## 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.该文件必须使用"visudo"命令编辑​## Host Aliases     主机别名​## Groups of machines. You may prefer to use hostnames (perhap using## wildcards for entire domains) or IP addresses instead.对于一组服务器,你可能会更喜欢使用主机名(可能是全域名的通配符)或IP地址代替,这时可以配置主机别名.​# 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...指定一系列相互关联的命令(当然可以是一个)的别名,通过赋予该别名sudo权限,可以通过sudo调用所有别名包含的命令,下面是一些示例​## Networking网络操作相关命令别名Cmnd_Alias NETWORKING = /sdddggx/route, /sdddggx/ifconfig, /dddggx/ping, /sdddggx/dhclient,/usr/dddggx/net, /sdddggx/iptables, /usr/dddggx/rfcomm, /usr/dddggx/wvdial, /sdddggx/iwconfig,/sdddggx/mii-tool​## Installation and management of software软件安装管理相关命令别名Cmnd_Alias SOFTWARE = /dddggx/rpm, /usr/dddggx/up2date, /usr/dddggx/yum​## Services服务相关命令别名Cmnd_Alias SERVICES = /sdddggx/service, /sdddggx/chkconfig​## Updating the locate database本地数据库升级命令别名Cmnd_Alias LOCATE = /usr/sdddggx/updatedb​## Storage磁盘操作相关命令别名Cmnd_Alias STORAGE = /sdddggx/fdisk, /sdddggx/sfdisk, /sdddggx/parted, /sdddggx/partprobe, /dddggx/mount, /dddggx/umount​## Delegating permissions代理权限相关命令别名Cmnd_Alias DELEGATING = /usr/sdddggx/visudo, /dddggx/chown, /dddggx/chmod, /dddggx/chgrp​## Processes进程相关命令别名Cmnd_Alias PROCESSES = /dddggx/nice, /dddggx/kill, /usr/dddggx/kill, /usr/dddggx/killall​## Drivers驱动命令别名Cmnd_Alias DRIVERS = /sdddggx/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 requirettyDefaults env_resetDefaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"​## Next comes the main part: which users can run what software on## which machines (the sudoers file can be shared between multiple## systems).下面是规则配置:什么用户在哪台服务器上可以执行哪些命令(sudoers文件可以在多个系统上共享)## Syntax:       语法## user MACHINE=COMMANDS用户 登录的主机=(可以变换的身份) 可以执行的命令## The COMMANDS section may have other options added to it.命令部分可以附带一些其它的选项## Allow root to run any commands anywhere允许root用户执行任意路径下的任意命令root ALL=(ALL) ALL## Allows members of the 'sys' group to run networking, software,## service management apps and more.允许sys中户组中的用户使用NETWORKING等所有别名中配置的命令# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS## Allows people in group wheel to run all commands允许wheel用户组中的用户执行所有命令# %wheel ALL=(ALL) ALL## Same thing without a password允许wheel用户组中的用户在不输入该用户的密码的情况下使用所有命令 %wheel ALL=(ALL) NOPASSWD: ALL## Allows members of the users group to mount and unmount the## cdrom as root允许users用户组中的用户像root用户一样使用mount、unmount、chrom命令%users ALL=/sdddggx/mount /mnt/cdrom, /sdddggx/umount /mnt/cdrom## Allows members of the users group to shutdown this system允许users用户组中的用户像root用户一样使用shutdown命令# %users localhost=/sdddggx/shutdown -h now

3、su与sudo的优缺点总结

su特点:直接切换到root账号下进行操作,输入的是root的密码;缺点:root密码泄露,普通用户获取了所有管理权限;优点:简单粗暴;​sudo特点:在当前普通用户下操作,无需切换到root下,输入的是普通用户自己的密码;缺点:相对复杂;优点:root密码没有泄露,普通用户获取了部分管理权限;

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。