linux command


Linux Command – su ใช้ในการ login ด้วย user id อื่น



su – <username>

$ su - staff



 su [options] [username]



เป็นคำสั่งที่ใช้ในการ login ด้วย user id อื่น โดยการสร้าง login session ใหม่หลังจาก ระบุ username ด้วยคำสั่ง su <username> ต้องทำการกรอก password ให้ถูกต้อง แต่สำหรับ session ที่เป็น user root อยู่แล้ว ไม่จำเป็นต้องกรอก password สำหรับการ su ไป user อื่นๆในระบบ



 -c, --command COMMAND
 Specify a command that will be invoked by the shell using its -c.

 The executed command will have no controlling terminal. This option cannot be used to execute interractive programs which need a controlling TTY.

 -, -l, --login
 Provide an environment similar to what the user would expect had the user logged in directly.

 When - is used, it must be specified before any username. For portability it is recommended to use it as last option, before any username. The other forms (-l and --login) do
 not have this restriction.

 -s, --shell SHELL
 The shell that will be invoked.

 The invoked shell is chosen from (highest priority first):

 The shell specified with --shell.

 If --preserve-environment is used, the shell specified by the $SHELL environment variable.

 The shell indicated in the /etc/passwd entry for the target user.

 /bin/sh if a shell could not be found by any above method.

 If the target user has a restricted shell (i.e. the shell field of this user's entry in /etc/passwd is not listed in /etc/shells), then the --shell option or the $SHELL
 environment variable won't be taken into account, unless su is called by root.

 -m, -p, --preserve-environment
 Preserve the current environment, except for:

 reset according to the /etc/login.defs options ENV_PATH or ENV_SUPATH (see below);

 reset to “<space><tab><newline>”, if it was set.

 If the target user has a restricted shell, this option has no effect (unless su is called by root).

 Note that the default behavior for the environment is the following:

 The $HOME, $SHELL, $USER, $LOGNAME, $PATH, and $IFS environment variables are reset.

 If --login is not used, the environment is copied, except for the variables above.

 If --login is used, the $TERM, $COLORTERM, $DISPLAY, and $XAUTHORITY environment variables are copied if they were set.

 Other environments might be set by PAM modules.



login(1), login.defs(5), sg(1), sh(1).



คำสั่ง Unix – Linux Command

Linux, Unix


Author: Suphakit Annoppornchai


One Thought to “su – Linux Command คำสั่ง login ด้วย user id อื่น”

Leave a Reply