Latest web development tutorials

Linux su command

Linux command Daquan Linux command Daquan

Linux su command to change to another user's identity, in addition to root, the need to type the user's password.

Access: All users.

grammar

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

Parameter Description:

  • -f or --fast not start reading files (such as csh.cshrc etc.), only for the csh or tcsh
  • -m does not change environmental variables when -p or --preserve-environment implementation of su
  • -c command or --command = command was changed to account for the USER user and executes instructions (command) and then change back to the original user
  • -s shell or --shell = shell shell specified to be executed (bash csh tcsh, etc.), default is / etc / passwd within the user (USER) shell
  • --help display documentation
  • --version Display version information
  • - -l Or --login this parameter after the addition, if re-login for the user, as the majority of environmental variables (HOME SHELL USER, etc.) are based on the user (USER) based, and work directory will change, if you do not specify USER, the default is the root
  • USER To change user account
  • ARG incoming new shell parameters

Examples

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

su -c ls root

Change account to root and pass -f parameter to the shell of the new Executive

su root -f

And change accounts for clsung clsung change the working directory to home directory (home dir)

su - clsung

Switch User

[email protected]:~$ whoami //显示当前用户
hnlinux
[email protected]:~$ pwd //显示当前目录
/home/hnlinux
[email protected]:~$ su root //切换到root用户
密码: 
[email protected]:/home/hnlinux# whoami 
root
[email protected]:/home/hnlinux# pwd
/home/hnlinux

Switch user, changing environment variables

[email protected]:~$ whoami //显示当前用户
hnlinux
[email protected]:~$ pwd //显示当前目录
/home/hnlinux
[email protected]:~$ su - root //切换到root用户
密码: 
[email protected]:/home/hnlinux# whoami 
root
[email protected]:/home/hnlinux# pwd //显示当前目录
/root

Linux command Daquan Linux command Daquan