Linux shell su command All In One

news/2025/3/6 18:30:29/文章来源:https://www.cnblogs.com/xgqfrms/p/18756083

Linux shell su command All In One

su !== sudo

substitute user => su, 替换用户/切换用户

substitute user do => su do

superuser do => sudo, 执行超级管理员用户权限

su

su - run a command with substitute user and group ID
su - 使用替代用户组 ID运行命令

$ man su$ man su > ~/Desktop/man-su.md$ cat ~/Desktop/man-su.md

image

$ cat ~/Desktop/man-su.md
SU(1)                                     User Commands                                    SU(1)NAMEsu - run a command with substitute user and group IDSYNOPSISsu [options] [-] [user [argument...]]DESCRIPTIONsu allows commands to be run with a substitute user and group ID.When called with no user specified, su defaults to running an interactive shell as root.When user is specified, additional arguments can be supplied, in which case they arepassed to the shell.For backward compatibility, su defaults to not change the current directory and to onlyset the environment variables HOME and SHELL (plus USER and LOGNAME if the target user isnot root). It is recommended to always use the --login option (instead of its shortcut -)to avoid side effects caused by mixing environments.This version of su uses PAM for authentication, account and session management. Someconfiguration options found in other su implementations, such as support for a wheelgroup, have to be configured via PAM.su is mostly designed for unprivileged users, the recommended solution for privilegedusers (e.g., scripts executed by root) is to use non-set-user-ID command runuser(1) thatdoes not require authentication and provides separate PAM configuration. If the PAMsession is not required at all then the recommended solution is to use commandsetpriv(1).Note that su in all cases uses PAM (pam_getenvlist(3)) to do the final environmentmodification. Command-line options such as --login and --preserve-environment affect theenvironment before it is modified by PAM.Since version 2.38 su resets process resource limits RLIMIT_NICE, RLIMIT_RTPRIO,RLIMIT_FSIZE, RLIMIT_AS and RLIMIT_NOFILE.OPTIONS-c, --command=commandPass command to the shell with the -c option.-f, --fastPass -f to the shell, which may or may not be useful, depending on the shell.-g, --group=groupSpecify the primary group. This option is available to the root user only.-G, --supp-group=groupSpecify a supplementary group. This option is available to the root user only. Thefirst specified supplementary group is also used as a primary group if the option--group is not specified.-, -l, --loginStart the shell as a login shell with an environment similar to a real login:•   clears all the environment variables except TERM and variables specified by--whitelist-environment•   initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH•   changes to the target user’s home directory•   sets argv[0] of the shell to '-' in order to make the shell a login shell-m, -p, --preserve-environmentPreserve the entire environment, i.e., do not set HOME, SHELL, USER or LOGNAME. Thisoption is ignored if the option --login is specified.-P, --ptyCreate a pseudo-terminal for the session. The independent terminal provides bettersecurity as the user does not share a terminal with the original session. This can beused to avoid TIOCSTI ioctl terminal injection and other security attacks againstterminal file descriptors. The entire session can also be moved to the background(e.g., su --pty - username -c application &). If the pseudo-terminal is enabled, thensu works as a proxy between the sessions (sync stdin and stdout).This feature is mostly designed for interactive sessions. If the standard input isnot a terminal, but for example a pipe (e.g., echo "date" | su --pty), then the ECHOflag for the pseudo-terminal is disabled to avoid messy output.-s, --shell=shellRun the specified shell instead of the default. The shell to run is selectedaccording to the following rules, in order:•   the shell specified with --shell•   the shell specified in the environment variable SHELL, if the--preserve-environment option is used•   the shell listed in the passwd entry of the target user•   /bin/shIf the target user has a restricted shell (i.e., not listed in /etc/shells), the --shelloption and the SHELL environment variables are ignored unless the calling user is root.--session-command=commandSame as -c, but do not create a new session. (Discouraged.)-w, --whitelist-environment=listDon’t reset the environment variables specified in the comma-separated list whenclearing the environment for --login. The whitelist is ignored for the environmentvariables HOME, SHELL, USER, LOGNAME, and PATH.-h, --helpDisplay help text and exit.-V, --versionPrint version and exit.SIGNALSUpon receiving either SIGINT, SIGQUIT or SIGTERM, su terminates its child and afterwardsterminates itself with the received signal. The child is terminated by SIGTERM, afterunsuccessful attempt and 2 seconds of delay the child is killed by SIGKILL.CONFIG FILESsu reads the /etc/default/su and /etc/login.defs configuration files. The followingconfiguration items are relevant for su:FAIL_DELAY (number)Delay in seconds in case of an authentication failure. The number must be anon-negative integer.ENV_PATH (string)Defines the PATH environment variable for a regular user. The default value is/usr/local/bin:/bin:/usr/bin.ENV_ROOTPATH (string), ENV_SUPATH (string)Defines the PATH environment variable for root. ENV_SUPATH takes precedence. Thedefault value is /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin.ALWAYS_SET_PATH (boolean)If set to yes and --login and --preserve-environment were not specified suinitializes PATH.The environment variable PATH may be different on systems where /bin and /sbin aremerged into /usr; this variable is also affected by the --login command-line optionand the PAM system setting (e.g., pam_env(8)).EXIT STATUSsu normally returns the exit status of the command it executed. If the command was killedby a signal, su returns the number of the signal plus 128.Exit status generated by su itself:1Generic error before executing the requested command126The requested command could not be executed127The requested command was not foundFILES/etc/pam.d/sudefault PAM configuration file/etc/pam.d/su-lPAM configuration file if --login is specified/etc/default/sucommand specific logindef config file/etc/login.defsglobal logindef config fileNOTESFor security reasons, su always logs failed log-in attempts to the btmp file, but it doesnot write to the lastlog file at all. This solution can be used to control su behavior byPAM configuration. If you want to use the pam_lastlog(8) module to print warning messageabout failed log-in attempts then pam_lastlog(8) has to be configured to update thelastlog file as well. For example by:session required pam_lastlog.so nowtmpHISTORYThis su command was derived from coreutils' su, which was based on an implementation byDavid MacKenzie. The util-linux version has been refactored by Karel Zak.SEE ALSOsetpriv(1), login.defs(5), shells(5), pam(8), runuser(1)REPORTING BUGSFor bug reports, use the issue tracker athttps://github.com/util-linux/util-linux/issues.AVAILABILITYThe su command is part of the util-linux package which can be downloaded from LinuxKernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/>.util-linux 2.38.1                          2022-05-11                                      SU(1)
eric@rpi3b:~ $ 

locale bugfix

$ man su
man: can't set the locale; make sure $LC_* and $LANG are correct
$ cat /etc/locale.gen$ sudo vim /etc/locale.gen$ sudo locale-gen
Generating locales (this might take a while)...en_GB.UTF-8... donezh_CN.UTF-8... done
Generation complete.$ locale
LANG=zh_CN.UTF-8
LANGUAGE=
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=zh_CN.UTF-8

切到帐号

$ su do

demos

树莓派电源管理 / Raspberry Pi Power Management

# iw
$ /sbin/iw dev wlan0 get power_save
Power save: off$ iw dev wlan0 get power_save
Power save: off
# iwconfig
$ iwconfig wlan0 power off
# iwconfig
eric@rpi3b:~ $ iwconfig
lo        no wireless extensions.eth0      no wireless extensions.wlan0     IEEE 802.11  ESSID:"603"  Mode:Managed  Frequency:2.437 GHz  Access Point: 00:12:93:18:AF:AF   Bit Rate=57.7 Mb/s   Tx-Power=31 dBm   Retry short limit:7   RTS thr:off   Fragment thr:offPower Management:offLink Quality=51/70  Signal level=-59 dBm  Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0Tx excessive retries:1  Invalid misc:0   Missed beacon:0
# iwconfig wlan0
eric@rpi3b:~ $ iwconfig wlan0
wlan0     IEEE 802.11  ESSID:"603"  Mode:Managed  Frequency:2.437 GHz  Access Point: 00:12:93:18:AF:AF   Bit Rate=43.3 Mb/s   Tx-Power=31 dBm   Retry short limit:7   RTS thr:off   Fragment thr:offPower Management:offLink Quality=49/70  Signal level=-61 dBm  Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0Tx excessive retries:1  Invalid misc:0   Missed beacon:0
# iwconfig wlan0 | grep "Power Management"
eric@rpi3b:~ $ iwconfig wlan0 | grep "Power Management"Power Management:off

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

https://www.cnblogs.com/xgqfrms/p/16972247.html

https://www.cnblogs.com/xgqfrms/p/16481735.html



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/894742.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

座椅控制器SCM

智能座椅控制器SCM是经纬恒润设计研发的车身舒适性控制模块,实现电动座椅14向位姿调节及通风、加热、腰托、按摩等控制功能。其基于人机交互和整车中央控制,匹配多种应用场景,实现迎宾、一键零重力、二排方便上下车等座舱内前后排座椅联动的姿态和空间自动调整。 智能…

React18 函数组件的底层渲染机制与形参props的使用细节

前言: Vue中的组件开发: 1.全局组件和局部组件 2.函数组件和类组件(vue3不具备functional函数组件) React中的组件化开发: 没有明确全局和局部的概念,可以理解为都是局部组件,不过可以把组件注册到React上,这样每个组件只要导入React中即可使用 1.函数组件 2.类组件 3.…

c# 托管堆和垃圾回收的clr的控制

前言 简单讲述一下垃圾回收,我们能做的一些控制。 正文 强制回收 class Program {static void Main(){var str = new StringBuilder();var x = "";for (int i = 0; i < 500; i++){x += "xxxxxxxxsadasdasdsadsaewqeqczxcxzgsfaswqeqwrqwewqeasdasqweqwrqsda…

PHP调用redis消息队列案例

一、代码实例://需要成功引入并使用redis$redis = RedisManager::$redis;// 生产者:将订单加入队列(右端插入)function producer($orderId,$redis) { $redis->rPush(task_queue, $orderId); print_r("<br/>追加入列<br/>"); print_r($or…

redis消息队列案例

一、代码实例://需要成功引入并使用redis$redis = RedisManager::$redis;// 生产者:将订单加入队列(右端插入)function producer($orderId,$redis) { $redis->rPush(task_queue, $orderId); print_r("<br/>追加入列<br/>"); print_r($or…

conda创建虚拟环境并安装tensorflow-gpu

conda创建虚拟环境并安装tensorflow-gpu 命令行查看自己可支持的cuda版本 nvidia-smi如图,CUDA Version后面的就是电脑显卡可支持的cuda版本,所以我们要装的cuda版本需要<=12.7(可向下兼容)。不需要在意其提供的版本号,该版本是最高可支持的cuda 1.安装下载cuda,cudnn…

Echarts如何分别设置PC端图表标题显示和移动端显示?

Echarts绘制图表的时候,PC端界面较大,可以很好的展示,但是移动端界面较窄,需要调整,所以分开设置就要用到 media方法: 实例: 移动端: 源码设置: 注意:media需要设置在series同级; 源码:media: [{query: {maxWidth: 767 // 假设移动设备的最大宽度是767px},option: …

【Webshell不出网】reGeorg和Pystinger的使用

reGeorg+Proxifier: 在实战情况下有时会遇到外网Getshell准备内网渗透的时候发现目标机器不出网,所以就会用映射,代理..等等方式进行上线。 reGeorg项目地址为: https://gitcode.net/mirrors/sensepost/reGeorg?utm_source=csdn_github_acceleratorProxifier地址: https:…

【测试】钩子测试

图片钩子测试 仅收集了访问数据,未使用任何js信息,未窃取任何cookie 只用于匿名数据收集,以及,好玩。

什么!GIS地形与数字孪生结合,竟然能做出如此有趣的效果!

山海鲸可视化支持添加ArcGIS和Cesium地形,并且添加后的GIS地形能够完美与整个数字孪生系统进行融合。同时,我们也可以对GIS地形进行编辑,通过鼠标点击圈选编辑区域,可以将区域内的地形压平、抬升或下沉,结合数字孪生能够实现许多有趣的效果。下面我们就来看看,如何在山海…