The difference between su and su-


 

Time:2018/3/12html

Author:xibeiyelangshell

Title:The difference between su and su-安全


1.su : run a command with substitute user and group ID.bash

2.su - : run a command with substitute user and group ID and change username path.htm

Example:blog

eg1.su - root is the same as su - just like login as root,
then the shell is login shell,which mean it will expericene a login process,
usually .bash_profile and .bashrc will be sourced.
進程

eg2.su root is the same as su like you open an interactive shell in root name,
then only .bashrc will be sourced.
it


 

說明:登錄

su命令和su -命令最大的本質區別就是:前者只是切換了root身份,但Shell環境仍然是普通用戶的Shell;然後者連用戶和Shell環境一塊兒切換成root身份了。只有切換了Shell環境纔不會出現PATH環境變量錯誤。su切換成root用戶之後,pwd一下,發現工做目錄仍然是普通用戶的工做目錄;而用su -命令切換之後,工做目錄變成root的工做目錄了。用echo $PATH命令看一下su和su -之後的環境變量有何不一樣。以此類推,要從當前用戶切換到其它用戶也同樣,應該使用su -命令。變量

語法:

$ su [user_name]
su 命令能夠用來交互地更改你的用戶ID和組ID。 Su是switch user 或set user id的一個縮寫。這個命令讓你開啓一個子進程,成爲新的用戶 ID 和賦予你存取與這個用戶ID 關聯全部文件的存取權限。所以,出於安全的考慮,你在實際轉換身份時,會被要求輸入這個用戶賬號的密碼。
若是沒有參數,su 命令將你轉換爲 root(系統管理員)。root 賬號有時也被稱爲超級用戶,由於這個用戶能夠存取系統中的任何文件。也正是這個緣由,許多人將su命令當作是 supper-user(超級用戶)的一個縮寫。固然,你必需要提供 root密碼。 想要回到你原先的用戶身份,不要再使用 su 命令,你只須要使用 exit命令退出你使用su命令而生成的新的對話進程。
$ su – username
一些配置文件是爲你的對話線索而設立的。當你使用命令 su username時,你的對話特徵和你原始的登陸身份同樣。若是你想要你的對話進程擁有轉換後的用戶 ID一致的特徵,你要使用短斜槓: su – username。

小結:

1)超級用戶root切換到普通用戶無需密碼
2)普通用戶切換到root帳號須要root密碼
3)普通用戶之間切換須要對應的帳號密碼


 

參考:https://www.cnblogs.com/Nice-Boy/p/6137955.html

相關文章
相關標籤/搜索