什麼是差別之間:
sudo su -
和
su -i
哪一個比另一個更受青睞?
-, -l, --login Start the shell as a login shell with an environment similar to a real login: o clears all the environment variables except TERM and variables specified by --whitelist-environment o initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH o changes to the target user's home directory o sets argv[0] of the shell to '-' in order to make the shell a login shell
和
su - run a command with substitute user and group ID
頁面摘錄man su
。
答案1
-i
該命令沒有參數su
,因此區別在於一個有效而另一個無效。
如果你的意思是su -l
,預設情況下它在 Ubuntu 機器上仍然不起作用,因為帳戶root
被鎖定並且沒有密碼可輸入。
-
和參數之間沒有區別-l
。它們都是同一選項的變體。您實際上man
在您的問題中包含了告訴我們這一點的頁面中的一行。
-
使用、-l
或參數(它們都是相同的)和不使用參數之間的區別--login
主要在您的帖子中包含的摘錄中進行了解釋。這部分講述了它在沒有參數的情況下做了什麼:
For backward compatibility, su defaults to not change the current directory and to only set the environment variables HOME and SHELL (plus USER and LOG‐
NAME if the target user is not root). It is recommended to always use the --login option (instead of its shortcut -) to avoid side effects caused by
mixing environments.
請注意,這su
不僅適用於root
.它不代表超級用戶就像評論一樣sudo
。它代表替代用戶並且您可以指定要用作參數的使用者以作為該使用者執行命令