Okay, so when I log in as root in my terminal using sudo, sudo -i, or su I get:
[dash@localhost IN => ~]$ su
Password
[root@localhost IN => /home/dash]$ (notice the $ instead of #, this could be a mistake I made when editing .bashrc & .bashprofile) (even though the last part of my .bashrc is \$)

Now, when I edit .bashrc & .bash_profile (as root)I see the changes only as long as I am root. When I close terminal and re-open it, the changes are gone. If I log in as root, however, the changes re-appear. Is it possible that there are 2 .bashrcs and 2 .bash_profiles? If so, does that mean that I changed the ones for the root user only?

On a different computer, I changed the .bashrc and .bash_profile as normal user (not root). The changes appeared only while I was NOT root. I heard that one of these two files is for normal terminal, and the other is for shells. If so, why did the changes appear only while I wasn't root, even though I put the same code in both files, rather than resorting to if ~/etc/.bashrc... ? (assuming that root is a shell)

  • 1
    Those files are store in the home folder which is unique for each user. ~/.bashrc when logged in as root is not the same file as ~/.bashrc when logged in as another user. ~ = the user’s home folder. – Appleoddity Nov 9 at 5:27
up vote 0 down vote accepted

First thing to note that there are separate .bashrc file for each user including root.

In your first case when you used command su then you become root user whose current directory is /home/dash. If you do echo $HOME then you will find that it is /root and if you edit .bashrc file then you are editing this file in /root directory means that you are editing .bashrc file for root user. So these changes will appear only when you login as root not as normal user.

In second case when you edited file as normal user then the changes will appear to normal user only as you changed the files for that user.

  • Is there a way to have root-like privileges without being root in terminal? That is, remaining logged in as your user, but still having elevated privileges? – Dash Conroy Nov 9 at 5:38
  • Also, shouldn't the changes made to the files remain even if you are root in terminal, as long as you haven't logged out of the computer? Because I heard that one file is for when you are the same user in terminal as in the computer, and the other is for when you are in SSH, or logged in as other users. – Dash Conroy Nov 9 at 5:45
  • @DashConroy you can use sudo to execute commands with root privilege while remaining logged as user – Debian_yadav Nov 9 at 6:26
  • Okay, that's good, but that means I have to retype my password with every command. Is there a way to get around this? – Dash Conroy Nov 10 at 6:45
  • @DashConroy edit sudoers file using visudo command to make sudo passwordless but it is not recommended. Second solution is to increase the time limit of sudo. Google it and you will find. – Debian_yadav Nov 10 at 7:26

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.