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

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

$ 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, 禁止转载 🈲️,侵权必究⚠️!