xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Linux shell su command All In One

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运行命令

su - switch user 切换用户

sudo === super user do

  1. 生效一次
  2. 需要输入密码

image

locale bugfix

切到帐号

demos

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

image

Linux shell & shell script & parent shell & child shell

login shell
logout shell

Raspberry Pi 使用 /etc/rc.local 来禁用 Wi-Fi 的电源管理 Power Management:off

  1. 问题描述 ❓

明明在命令行测试/etc/rc.local 脚本没有问题,
但是为什么 reboot 重启系统后,在命令行中却没有输出 /etc/rc.local 脚本中的 echo 语句呢?

image

image

/etc/rc.local

~/.bashrc / /home/eric/.bashrc

  1. 问题分析

使用 sudo 测试 shell 脚本可以成功,说明该 shell 脚本运行没有问题,即不存在脚本语法和权限问题!

/etc/rc.local/home/eric/.bashrc / ~/.bashrc 脚本文件的所有者权限不同, shell 脚本运行的 shell 进程也不同;

每次启动一个新 shell, 都会执行一次 .bashrc 脚本文件 ✅

  1. 总结

/etc/rc.local/home/eric/.bashrc / ~/.bashrc 脚本文件的所有者和权限不同,shell 脚本运行的 shell 进程也不同;

因为,用户 eric 使用 SSH 远程登录系统后,~/.bashrc 脚本运行在 eric 的子 shell 进程中, 命令行界面输出的 echo 语句仅仅是 /home/eric/.bashrc 中的;
/etc/rc.local 运行在 root 的子 shell 进程中,所以看不到 /etc/rc.local 脚本中的 echo 语句输出; ✅

即, 由于 /etc/rc.local 脚本的所有者是 root,输出的 echo 语句是对当前登录用户 eric 是不可见的,但是 /etc/rc.local 脚本会自动执行,当有用户登录到系统的时候;

su vs sudo

鸟哥的 Linux 私房菜

https://linux.xgqfrms.xyz/linux_basic/0410accountmanager.htm#:~:text=的用法啦!-,su,-su 是最

https://linux.xgqfrms.xyz/linux_basic/0410accountmanager.htm#:~:text=來處理即可!-,sudo,-相對於 su

第十三章、Linux帐号管理与ACL权限设置

https://linux.vbird.org/linux_basic/centos7/0410accountmanager.php

13.4 使用者身份切換

https://linux.vbird.org/linux_basic/centos7/0410accountmanager.php#userswitch

image
image

image

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

shell script 2>&1 二合一 输出错误信息 log

image

image

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

shell 脚本获取当前系统的时间戳, 写入 log 文件 ?

2>&1 二合一重定向标准错误输出到标准输出

标准输入 stdin
标准输出 stdout
标准错误输出 stderr

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

父子 shell 与 环境变量

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

rc.local

multiuser

runlevel

https://unix.stackexchange.com/questions/49626/purpose-and-typical-usage-of-etc-rc-local

whiptail --msgbox

https://stackoverflow.com/questions/73325002/handle-errors-in-whiptail-gauge-with-a-msgbox

.profile 用户级启动配置文件

Linux 系统中登录 shell 的时候,会从下面的 5 个启动文件里读取命令;

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

image

image

.profile

~/.profile
~/.bash_profile
~/.bash_login

the difference between boot or login

Running A Program At Start UP A Beginner's Guide.pdf / login-boot.pdf

https://github.com/xgqfrms/cdn/blob/gh-pages/Linux/login-boot.pdf

image

https://www.cnblogs.com/xgqfrms/p/17323041.html#5168612

refs

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

https://www.atatus.com/blog/essential-guide-to-sudo-and-su-in-linux/

https://superuser.com/questions/408990/how-do-i-log-out-of-sudo-su



©xgqfrms 2012-2025

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

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


posted @   xgqfrms  阅读(5)  评论(5编辑  收藏  举报
点击右上角即可分享
微信分享提示