Wednesday, October 24, 2018

linux - What is the difference between "sudo -i" and "sudo bash -l"




There is a recent question regarding multiple sysadmins working as root, and sudo bash -l was referenced.



I searched for this on google and SE, but I don't understand the difference between sudo bash -l and sudo -i.



From the man pages for bash and sudo it seems that the difference may be that sudo bash -l runs ~/.bash_profile, ~/.bash_login, and ~/.profile, and ~/.bash_logout of the root user, but from testing myself it looks like it runs the normal user's .bashrc and not the root one. I may have misunderstood which user the ~ expression is referencing in the man pages.
Clarification of the difference and usage scenarios would be appreciated.


Answer



They differ in that if the root user login shell specified in /etc/passwd is not bash, then the second command will get you a bash shell as root while the first command will use whatever the interactive shell the root user has.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...