标签:san ble 切换用户 warning 注意 directory pwd touch 格式
su: 即 switch user,命令可以切换用户身份,并且以指定用户的身份执行命令
su [options...] [-] [user [args...]]
-l --login su -l UserName 相当于 su - UserName
-c, --command <command> pass a single command to the shell with -c
su [-] UserName -c ‘COMMAND‘
范例:
[root@centos8 ~]#getent passwd mage
mage:x:1001:1001::/home/mage:/bin/bash
[root@centos8 ~]#usermod -s /bin/false mage
[root@centos8 ~]#getent passwd mage
mage:x:1001:1001::/home/mage:/bin/false
[root@centos8 ~]#su - mage
Last login: Fri Mar 27 09:18:57 CST 2020 on pts/0
[root@centos8 ~]#whomai
-bash: whomai: command not found
[root@centos8 ~]#whoami
root
范例:
[root@centos8 ~]#su -s /sbin/nologin wang
This account is currently not available.
[root@centos8 ~]#whoami
root
[root@centos8 ~]#su -s /bin/false wang
[root@centos8 ~]#whoami
root
范例:
[wang@centos8 ~]$su - root -c "getent shadow"
范例:
[root@centos8 ~]#su - wang -c ‘touch wang.txt‘
[root@centos8 ~]#ll ~wang/
total 0
-rw-rw-r-- 1 wang wang 0 Mar 27 09:31 wang1.txt
-rw-rw-r-- 1 wang wang 0 Mar 27 09:32 wang2.txt
范例:
[root@centos8 ~]#su bin
This account is currently not available.
[root@centos8 ~]#su -s /bin/bash bin
bash-4.4$ whoami
bin
bash-4.4$
[root@centos8 ~]#getent passwd tss
tss:x:59:59:Account used by the trousers package to sandbox the tcsd
daemon:/dev/null:/sbin/nologin
[root@centos8 ~]#su - -s /bin/bash tss
Last login: Fri Mar 27 09:46:43 CST 2020 on pts/0
su: warning: cannot change directory to /dev/null: Not a directory
-bash: /dev/null/.bash_profile: Not a directory
[tss@centos8 root]$pwd
/root
[tss@centos8 root]$whoami
tss
标签:san ble 切换用户 warning 注意 directory pwd touch 格式
原文地址:https://www.cnblogs.com/bpzblog/p/13290069.html