Linux命令 - su命令
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash

·
Linux命令 - su命令
su是swith user的缩写,在Linux中 su 命令可让用户暂时变更登入的身份,除 root 外变更时须输入所要变更的用户帐号与密码。
1.语法:
su [参数] [-] [用户帐号]
2.功能:
变更用户身份,若不指定用户帐号,则预设变更为root。
3.参数:
-c<指令>或--command=<指令> 执行完指定的指令后,即恢复原来的身份。
-f或--fast 适用于csh与tsch,使shell不用去读取启动文件。
--l或--login 改变身份时,也同时变更工作目录,以及HOME,SHELL,USER,LOGNAME。此外,也会变更PATH变量。
-m,-p或--preserve-environment 变更身份时,不要变更环境变量。
-s<shell>或--shell=<shell> 指定要执行的shell(bash csh tcsh 等),预设值为 /etc/passwd 内的该使用者(USER) shell。
4.常用范例:
例一:变更帐号为 root 并在执行 ls 指令后退出变回原使用者
命令:su -c ls root
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
变更帐号为 root 并在执行 ls 指令后退出变回原使用者。
[root@localhost ~]# su -c ls root
公共 视频 文档 音乐 anaconda-ks.cfg
模板 图片 下载 桌面 initial-setup-ks.cfg
例二:切换用户
命令: su root
testuser切换成root,相当于用户改成root但是操作的是testuser环境
小权限切换大权限要求输入密码;大权限切换小权限不需要输入密码。
切换用户,只能获得用户的执行权限,不能获得环境变量。
[testuser@localhost ~]$ whoami //显示当前用户
testuser
[testuser@localhost ~]$ pwd //显示当前目录
/home/testuser
[testuser@localhost ~]$ su root //切换到root用户
密码:
[root@localhost testuser]# whoami
root
[root@localhost testuser]# pwd
/home/testuser
例三:切换用户,改变环境变量
命令:su - root
testuser切换成root,相当于用户改成root,操作的是root环境。即变更帐号为 root 并改变工作目录至 root 的家目录。
切换到用户并获得该用户的环境变量及执行权限。
[testuser@localhost ~]$ whoami
testuser
[testuser@localhost ~]$ pwd
/home/testuser
[testuser@localhost ~]$ su - root
密码:
[root@localhost ~]# whoami
root
[root@localhost ~]# pwd
/root
阅读全文
AI总结




A beautiful web dashboard for Linux
最近提交(Master分支:6 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
相关推荐
查看更多
linux-dash

A beautiful web dashboard for Linux
linux-dash

A beautiful web dashboard for Linux
linux-dash

热门开源项目
活动日历
查看更多
直播时间 2025-03-13 18:32:35

全栈自研企业级AI平台:Java核心技术×私有化部署实战
直播时间 2025-03-11 18:35:18

从0到1:Go IoT 开发平台的架构演进与生态蓝图
直播时间 2025-03-05 14:35:37

国产工作流引擎 终结「996」开发困局!
直播时间 2025-02-25 14:38:13

免费开源宝藏 ShopXO,电商系统搭建秘籍大公开!
直播时间 2025-02-18 14:31:04

从数据孤岛到数据智能 - 企业级数据管理利器深度解析
所有评论(0)