sudo -i和sudo su -的区别

-柚子皮-
人工智能领域优质创作者
博客专家认证
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.
...全文
4383 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
winskygod 2016-03-10
  • 打赏
  • 举报
回复
Hi,我要是想配置sudo -i,需要怎么做呢,我没有找到这个的配置方法。
boy_li02 2014-12-09
  • 打赏
  • 举报
回复
用 man sudu 查询一下呗
奔跑的路 2014-12-08
  • 打赏
  • 举报
回复
「已注销」 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
  • 打赏
  • 举报
回复
学习!!!!!!!!!!!!!!

2,163

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 UNIX文化
社区管理员
  • UNIX文化社区
  • 文天大人
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧