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
- 生效一次
- 需要输入密码

locale
bugfix
切到帐号
demos
树莓派电源管理 / Raspberry Pi
Power Management
Linux shell & shell script & parent shell & child shell
login shell
logout shell
Raspberry Pi 使用
/etc/rc.local
来禁用 Wi-Fi 的电源管理Power Management:off
- 问题描述 ❓
明明在命令行测试/etc/rc.local
脚本没有问题,
但是为什么 reboot 重启系统后,在命令行中却没有输出 /etc/rc.local
脚本中的 echo 语句呢?
/etc/rc.local
/etc/rc.local
~/.bashrc
/ /home/eric/.bashrc
~/.bashrc
/ /home/eric/.bashrc
- 问题分析
使用 sudo 测试 shell 脚本可以成功,说明该 shell 脚本运行没有问题,即不存在脚本语法和权限问题!
/etc/rc.local
与 /home/eric/.bashrc
/ ~/.bashrc
脚本文件的所有者
和权限
不同, shell 脚本运行的 shell 进程
也不同;
每次启动一个新 shell
, 都会执行一次
.bashrc 脚本文件 ✅
- 总结
/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
https://www.cnblogs.com/xgqfrms/p/16972247.html
shell script 2>&1
二合一 输出错误信息 log
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
.profile
~/.profile
~/.bash_profile
~/.bash_login
the difference between
boot
orlogin
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
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, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/18756083
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步