[SOLVED] Automate sourcing .bashrc when su - to root
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need to source the my /home/me/.bashrc file every time I "su -" to root. Is there any way to automate this? I cannot edit any thing in the root's environment as it is shared by people.
uhm... usually /root/.bashrc has the answer for you, you may also look if you are using /root/.profile file, anyways. On the file that your shell is using, you may add
When you log in, you get your .bashrc (/home/you/.bashrc). When you
"su -" to root you get root's .bashrc (/root/.bashrc). To overwrite root's bashrc with yours for that session, you type: ". /home/you/.bashrc" Now, I have to type this every time I su to root. And I was wondering how can I avoid typing this and automate this process.
If you do NOT use the "-", you do NOT get a login shell and your shell remains as it was, ie, the previous .bashrc of your shell remains. "-" is equivalent to "-l" see man su. Maybe that will work for you.
to the end of /root/bash_profile. Note it's not behaviour you would want to see on publicly accessible multiuser machines, just like the kernel doesn't read the firewall configuration but gets it pushed through the iptables binary, root should not read files owned by unprivileged users.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.