sudo su 和 su - 的区别!?

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
头像
九天星
帖子: 1441
注册时间: 2007-07-14 20:45

sudo su 和 su - 的区别!?

#1

帖子 九天星 » 2015-10-11 13:57

请教:sudo su 和su -的区别是什么?


谢谢!
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: sudo su 和 su - 的区别!?

#2

帖子 vickycq » 2015-10-11 14:36

搭车问一下
用 su - 建立 root login shell 后 who am i 为何不是 root

代码: 全选

asd@localhost ~ $ su -
Password: 
localhost ~ # who am i
asd    pts/3        2015-10-10 19:54 (:0)
localhost ~ # 
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: sudo su 和 su - 的区别!?

#3

帖子 poloshiao » 2015-10-11 14:38

http://manpages.ubuntu.com/manpages/viv ... /su.1.html
su - change user ID or become superuser
su [options] [username]

1. su
後面沒有使用者帳號
預設更換為 root
1-1. sudo su
使用 root 權限 執行 su
意思是 原來登入的使用者 並非 root
1-1-1. http://askubuntu.com/questions/70534/wh ... -i-sudo-su
sudo su allows you to open a shell as another user (including root)
1-2. su -
http://unix.stackexchange.com/questions ... ot-just-su
Why do we use su - and not just su?
头像
九天星
帖子: 1441
注册时间: 2007-07-14 20:45

Re: sudo su 和 su - 的区别!?

#4

帖子 九天星 » 2015-10-11 15:24

vickycq 写了:搭车问一下
用 su - 建立 root login shell 后 who am i 为何不是 root

代码: 全选

asd@localhost ~ $ su -
Password: 
localhost ~ # who am i
asd    pts/3        2015-10-10 19:54 (:0)
localhost ~ # 

输入su -指令后,接下来要输入的密码是ROOT密码,可这个密码我根本没有啊,好像是系统自动生成的。我能自已更改吗?更改后对系统安全性有什么影响?
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: sudo su 和 su - 的区别!?

#5

帖子 vickycq » 2015-10-11 16:21

九天星 写了: 输入su -指令后,接下来要输入的密码是ROOT密码,可这个密码我根本没有啊,好像是系统自动生成的。我能自已更改吗?更改后对系统安全性有什么影响?
Ubuntu 默认禁用 root 账户(无root密码),可用 sudo passwd root 设置 root 密码,启用 root 账户。
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
头像
PithornDawn
帖子: 456
注册时间: 2012-04-14 11:00
系统: ArchLinux
联系:

Re: sudo su 和 su - 的区别!?

#6

帖子 PithornDawn » 2015-10-11 16:42

我很好奇为什么会有把 - 作为命令操作对象的。。

代码: 全选

cd -
su -
什么的,完全想不到。。
My personal blog

毛概老师:大家知道一个有名的空想社会主义吗?同学:乌邦图

用Linux有感:
得,用了1年多linux,感觉自己还是个菜鸟。。。
用了2年了,感觉自己还是一般菜。。。
第3年...头半年感觉和去年没啥变化。。。后半年算是能发挥点主观能动性了吧。。
第4年。。感觉自己算个伪Geek了
第5年,虽然有同学管我叫大神,但我还是觉得自己菜的一笔。。
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: sudo su 和 su - 的区别!?

#7

帖子 vickycq » 2015-10-11 16:48

PithornDawn 写了:我很好奇为什么会有把 - 作为命令操作对象的。。

代码: 全选

cd -
su -
什么的,完全想不到。。
1.

代码: 全选

 cd - == cd $OLDPWD
2.
man su
使用 su -l 时,-l 可以省略为 -
-, -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.
怎么制定开关的格式 是开发者的自由
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: sudo su 和 su - 的区别!?

#8

帖子 poloshiao » 2015-10-11 17:44

搭车问一下
用 su - 建立 root login shell 后 who am i 为何不是 root
代碼:
asd@localhost ~ $ su -
Password:
localhost ~ # who am i
asd pts/3 2015-10-10 19:54 (:0)
實作一下 (沒有啟用 root 帳號及密碼)
username@Server06:~$ whoami
username
username@Server06:~$ su -
密码:
su:认证失败
username@Server06:~$ sudo su -
[sudo] username 的密码:
root@Server06:~# whoami
root
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: sudo su 和 su - 的区别!?

#9

帖子 vickycq » 2015-10-11 17:49

poloshiao 写了: 實作一下 (沒有啟用 root 帳號及密碼)
username@Server06:~$ whoami
username
username@Server06:~$ su -
密码:
su:认证失败
username@Server06:~$ sudo su -
[sudo] username 的密码:
root@Server06:~# whoami
root
查了一下,这个 who am i 和 whoami 还不一样
http://unix.stackexchange.com/questions ... ew-user-id
http://www.linuxforums.org/forum/red-ha ... mmand.html
https://kunaljain.wordpress.com/2007/12 ... -who-am-i/
http://www.tek-tips.com/viewthread.cfm?qid=1565223

另外请教一下
sudo su 这种用法的意义是什么?
和 su 相比 最终进入的环境有何区别?
除了对付 Ubuntu 默认无 root 密码之外
:Faint
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: sudo su 和 su - 的区别!?

#10

帖子 poloshiao » 2015-10-11 20:14

查了一下,这个 who am i 和 whoami 还不一样
1. http://unix.stackexchange.com/questions ... ew-user-id
“who am i” after “su” not showing new user id?
1-1. man who
who - show who is logged on
who [OPTION]... [ FILE | ARG1 ARG2 ]
If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.
-m only hostname and user associated with stdin.
'who am i' (or who with any two arguments) is the same as 'who -m' and should give you the hostname and user associated with STDIN.

2. http://manpages.ubuntu.com/manpages/viv ... ami.1.html
whoami - print effective userid
sudo su 这种用法的意义是什么?
和 su 相比 最终进入的环境有何区别?
3. http://askubuntu.com/questions/70534/wh ... -i-sudo-su
如果使用 非 root 登入 例如 myuser
su 表示 使用 myuser 權限執行 su 指令
sudo su 表示 使用 root 權限執行 su 指令
3-1. http://unix.stackexchange.com/questions ... ot-just-su
su just switches the user, providing a normal shell with an environment nearly the same as with the old user.
無論 sudo su 或 su 如果成功執行 都只是切換為 root 但是 shell 沒改變
3-2. 以上是依照上面這一篇文章意譯 如果翻譯錯了 歡迎更正
回复