English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux su Befehl

Linux Command大全

Linux su (vollständiger englischer Name: switch user) Befehl wird verwendet, um den Benutzeraccount zu ändern, außer root, ist das Passwort des Benutzers erforderlich.

Berechtigungen: Alle Benutzer.

Syntax

su [-fmp] [-c command] [-s shell] [--help] [--version] [-] [USER [ARG]]

Parameterbeschreibung:

  • -f oder --fast liest keine Startdateien (wie csh.cshrc usw.), wird nur für csh oder tcsh verwendet
  • -m -p oder --preserve-environment ändert die Umgebungsvariablen nicht, wenn su ausgeführt wird
  • -c command oder --command=command ändert den Benutzeraccount zu USER und führt den Befehl (command) aus, bevor er zum ursprünglichen Benutzer zurückkehrt
  • -s shell oder --shell=shell spezifiziert den auszuführenden Shell (bash csh tcsh usw.), die Voreinstellung ist /etc/passwd The shell of the user (USER) inside
  • --help Display the help file
  • --version Display version information
  • - -l or --Adding this parameter to login is like re-login as the user, most environment variables (HOME, SHELL, USER, etc.) are based on the user (USER), and the working directory will also change. If USER is not specified, it defaults to root
  • USER The user account to be changed
  • ARG Pass new shell parameters

Online Examples

Change account to root and exit after executing ls command to return to the original user

su -c ls root

Change account to root and pass -f parameter for the new executed shell

su root -f

Change account to clsung and change working directory to clsung's home directory (home dir)

su - clsung

Switch User

[email protected]:~$ whoami //Show Current User
hnlinux
[email protected]:~$ pwd //Show Current Directory
/home/hnlinux
[email protected]:~$ su root //Switch to root User
Password: 
[email protected]:/home/hnlinux# whoami 
root
[email protected]:/home/hnlinux# pwd
/home/hnlinux

Switch User, Change Environment Variables

[email protected]:~$ whoami //Show Current User
hnlinux
[email protected]:~$ pwd //Show Current Directory
/home/hnlinux
[email protected]:~$ su - root //Switch to root User
Password: 
[email protected]:/home/hnlinux# whoami 
root
[email protected]:/home/hnlinux# pwd //Show Current Directory
/root

Linux Command大全