菜鸟提问,请教sudo su和sudo -i的区别。

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

菜鸟提问,请教sudo su和sudo -i的区别。

#1

帖子 xiajiwai » 2012-04-30 9:45

问题如题,希望各位能帮小弟解释一下。
多谢!!! :em01
头像
YeLee
论坛版主
帖子: 26406
注册时间: 2008-08-13 8:48
系统: Fundu i64
来自: 东海硇州,一双管钥。
联系:

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#2

帖子 YeLee » 2012-04-30 10:13

man sudo
-i [command]
The -i (simulate initial login) option runs the shell
specified by the password database entry of the target user
as a login shell. This means that login-specific resource
files such as .profile or .login will be read by the shell.
If a command is specified, it is passed to the shell for
execution via the shell's -c option. If no command is
specified, an interactive shell is executed. sudo attempts
to change to that user's home directory before running the
shell. The security policy shall initialize the
environment to a minimal set of variables, similar to what
is present when a user logs in. The Command Environment
section in the sudoers(5) manual documents how the -i
option affects the environment in which a command is run
when the sudoers policy is in use.
su?通过sudo运行su,用的是当前用户密码,而su默认是root密码。
◎当我站在道德的高度上俯视别人的时候,发现自己是多么渺小。
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关
zf123
帖子: 322
注册时间: 2011-05-31 17:35

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#3

帖子 zf123 » 2012-04-30 10:19

让我来说吧:
sudo : 暂时切换到超级用户模式以执行超级用户权限,提示输入密码时该密码为当前用户的密码,而不是超级账户的密码。不过有时间限制,Ubuntu默认为一次时长15分钟。
su : 切换到某某用户模式,提示输入密码时该密码为切换后账户的密码,用法为“su 账户名称”。如果后面不加账户时系统默认为root账户,密码也为超级账户的密码。没有时间限制。
sudo -i: 为了频繁的执行某些只有超级用户才能执行的权限,而不用每次输入密码,可以使用该命令。提示输入密码时该密码为当前账户的密码。没有时间限制。执行该命令后提示符变为“#”而不是“$”。想退回普通账户时可以执行“exit”或“logout” 。
我知道的就这么多,不知道有没有帮助你。
头像
YeLee
论坛版主
帖子: 26406
注册时间: 2008-08-13 8:48
系统: Fundu i64
来自: 东海硇州,一双管钥。
联系:

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#5

帖子 YeLee » 2012-04-30 10:29

:em09
◎当我站在道德的高度上俯视别人的时候,发现自己是多么渺小。
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关
头像
qy117121
论坛版主
帖子: 50587
注册时间: 2007-12-14 13:40
系统: Winbuntu
来自: 志虚国乌由市
联系:

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#6

帖子 qy117121 » 2012-04-30 10:32

photor 写了:人家是问“sudo su”和“sudo -i”的区别,2、3楼答非所问 :em09
渠月 · QY   
本人只会灌水,不负责回答问题
无聊可以点一下→ http://u.nu/ubuntu

邮箱 chuan@ubuntu.org.cn
头像
男菜鸟
帖子: 1382
注册时间: 2008-12-16 14:01
来自: 漂在江湖

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#7

帖子 男菜鸟 » 2012-04-30 11:06

mark
头像
onshoestring
论坛版主
帖子: 4666
注册时间: 2009-09-06 5:53

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#8

帖子 onshoestring » 2012-04-30 11:08

简单说就是shell环境不一样,具体要看看鸟哥的linxu私房菜第十一章,login shell 和 non-login shell的区别。

su non-login shell
sudo -i simulate initial login
The -i (simulate initial login) option runs the shell specified by the password database entry of the target user as a login shell.
The Command Environment section in the sudoers(5) manual documents how the -i option affects the environment in which a command is run when the sudoers policy is in use.
上次由 onshoestring 在 2012-04-30 11:11,总共编辑 1 次。
jtshs256
帖子: 22323
注册时间: 2010-07-19 21:41
系统: OS X

菜鸟提问,请教sudo su和sudo -i的区别。

#9

帖子 jtshs256 » 2012-04-30 11:09

su 的比较怪,貌似既不是 login 又不是 nonlogin,sudo -i 是 login shell 吧…
躺平
xiajiwai
帖子: 13
注册时间: 2011-08-08 0:14

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#10

帖子 xiajiwai » 2012-04-30 13:54

多谢楼上的几位!!我的问法有问题,不好意思。 :em06

我问的的确是“sudo su”和“sudo -i”的区别,望高手们能更通俗点的指点一下小弟。
头像
自由建客
帖子: 13468
注册时间: 2008-07-30 23:21
系统: Debian stable AMD64

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#11

帖子 自由建客 » 2012-04-30 17:32

看来有必要写篇《sudo 论》了!
头像
onshoestring
论坛版主
帖子: 4666
注册时间: 2009-09-06 5:53

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#12

帖子 onshoestring » 2012-04-30 18:37

xiajiwai 写了:多谢楼上的几位!!我的问法有问题,不好意思。 :em06

我问的的确是“sudo su”和“sudo -i”的区别,望高手们能更通俗点的指点一下小弟。
水平低只能看到:
sudo -i 直接运行sudo命令加-i参数
sudo su 运行sudo命令给su命令提权,运行su命令。
sudo -i 运行结果 PWD=/root
sudo su 运行结果 PWD=/home/用户名(当前用户主目录)
jtshs256
帖子: 22323
注册时间: 2010-07-19 21:41
系统: OS X

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#13

帖子 jtshs256 » 2012-04-30 18:47

login.defs
躺平
头像
ahwad
帖子: 1116
注册时间: 2009-05-06 0:36

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#14

帖子 ahwad » 2012-04-30 20:34

还是3L 说的明白,mark
 
xiajiwai
帖子: 13
注册时间: 2011-08-08 0:14

Re: 菜鸟提问,请教sudo su和sudo -i的区别。

#15

帖子 xiajiwai » 2012-05-01 14:16

多谢高手指点,小弟明白多了。

剩下的我再自己查查。 :em01
回复