sudo -i和sudo su -的区别

-柚子皮- aa NLP对话+推荐算法  2014-11-23 12:58:31
sudo -i和sudo su -的区别
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.
...全文
3471 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
winskygod 2016-03-10
Hi,我要是想配置sudo -i,需要怎么做呢,我没有找到这个的配置方法。
回复
boy_li02 2014-12-09
用 man sudu 查询一下呗
回复
奔跑的路 2014-12-08
回复
li4c 2014-12-08
学习了
回复
-柚子皮- 2014-11-23
sudo su - This time it is a login shell, so /etc/profile, .profile and .bashrc are executed and you will find yourself in root's home directory with root's environment. sudo -i It is nearly the same as sudo su - 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, .bashrc or .login will be read and executed by the shell. sudo /bin/bash This means that you call sudo with the command /bin/bash. /bin/bash is started as non-login shell so all the dot-files are not executed, but bash itself reads .bashrc of the calling user. Your environment stays the same. Your home will not be root's home. So you are root, but in the environment of the calling user. sudo -s reads the $SHELL variable and executes the content. If $SHELL contains /bin/bash it invokes sudo /bin/bash (see above). Check: To check if you are in a login shell or not (works only in bash because shopt is a builtin command): shopt -q login_shell && echo 'Login shell' || echo 'No login shell' http://askubuntu.com/questions/376199/sudo-su-vs-sudo-i-vs-sudo-bin-bash-when-does-it-matter-which-is-used
回复
-柚子皮- 2014-11-23
sudo : 暂时切换到超级用户模式以执行超级用户权限,提示输入密码时该密码为当前用户的密码,而不是超级账户的密码。不过有时间限制,Ubuntu默认为一次时长15分钟。 su : 切换到某某用户模式,提示输入密码时该密码为切换后账户的密码,用法为“su 账户名称”。如果后面不加账户时系统默认为root账户,密码也为超级账户的密码。没有时间限制。 sudo -i: 为了频繁的执行某些只有超级用户才能执行的权限,而不用每次输入密码,可以使用该命令。提示输入密码时该密码为当前账户的密码。没有时间限制。执行该命令后提示符变为“#”而不是“$”。想退回普通账户时可以执行“exit”或“logout” 。 sudo -i 直接运行sudo命令加-i参数 sudo su 运行sudo命令给su命令提权,运行su命令。 sudo -i 运行结果 PWD=/root sudo su 运行结果 PWD=/home/用户名(当前用户主目录) http://forum.ubuntu.org.cn/viewtopic.php?t=372636
回复
zhxianbin 2014-11-23
学习!!!!!!!!!!!!!!
回复
发帖
UNIX文化
创建于2007-08-27

2154

社区成员

Linux/Unix社区 UNIX文化
申请成为版主
帖子事件
创建了帖子
2014-11-23 12:58
社区公告
暂无公告