Want to preserve bashrc and vimrc when switching to non-root users
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm on a multi-user system. I have sudo b/c I'm responsible I guess. Sometimes, I want to switch to another user to help them do something, but I have a tricked-out bashrc/vimrc and I'd like to keep those.
For root, it's pretty easy. In my .bashrc
:
alias sudo='sudo '
alias -- -i='bash --rcfile $HOME/.bashrc'
export HOME="$( cd "$( dirname "$BASH_SOURCE[0]" )" >/dev/null && pwd )"
Basically, this means sudo -i
makes me root, sources my .bashrc
, and keeps my $HOME
as /home/jeremy
instead of /root
, meaning vim looks in the proper place for colors and rcfiles and things.
I want to do something similar with becoming other users. The ideal:
source my
.bashrc
; get vim to use my.vim/
stuff likevimrc
,colors/
, etc.doesn't hardcode paths -- on some systems I'm
jeremy
; on others I'mjdr
, etc.requires minimal extra typing for all of this to work by aliasing or function-ing the crap out of things.
For root, I was able to alias -i
to another command entirely that did what I wanted. man bash
doesn't list any options to do things as another user. man sudo
does, but then I wouldn't have any options to source a .bashrc
. su
seemed promising, as man su
says that su -m
preserves environment and doesn't set USER or HOME, but I'd have to sudo su -m
which sets my USER to root
. I can't add in commands using &&
or something because I would need the commands to run in the new shell instead of after that shell exits. In short, none of the commands I know of can do what I want.
The closest I was able to come was sudo -Esu user
, which makes me user
and keeps any vars I've exported. I could put something like export x=". $HOME/.bashrc"
in my .bashrc
and then eval $x
when I become user
, but that gives permissions errors, and setting +x on .bashrc
isn't sufficient because my home directory's default permissions prevent access by other users and I'm not sure I'd want to change that unless there's no other option. Not all users I'm becoming have privileges so I can't just sudo
my way in.
TL;DR: become another user while retaining my current user's aliases, functions, PS1, PROMPT_COMMAND, and vim configuration. Bash 4.2
bash sudo users su
add a comment |Â
up vote
0
down vote
favorite
I'm on a multi-user system. I have sudo b/c I'm responsible I guess. Sometimes, I want to switch to another user to help them do something, but I have a tricked-out bashrc/vimrc and I'd like to keep those.
For root, it's pretty easy. In my .bashrc
:
alias sudo='sudo '
alias -- -i='bash --rcfile $HOME/.bashrc'
export HOME="$( cd "$( dirname "$BASH_SOURCE[0]" )" >/dev/null && pwd )"
Basically, this means sudo -i
makes me root, sources my .bashrc
, and keeps my $HOME
as /home/jeremy
instead of /root
, meaning vim looks in the proper place for colors and rcfiles and things.
I want to do something similar with becoming other users. The ideal:
source my
.bashrc
; get vim to use my.vim/
stuff likevimrc
,colors/
, etc.doesn't hardcode paths -- on some systems I'm
jeremy
; on others I'mjdr
, etc.requires minimal extra typing for all of this to work by aliasing or function-ing the crap out of things.
For root, I was able to alias -i
to another command entirely that did what I wanted. man bash
doesn't list any options to do things as another user. man sudo
does, but then I wouldn't have any options to source a .bashrc
. su
seemed promising, as man su
says that su -m
preserves environment and doesn't set USER or HOME, but I'd have to sudo su -m
which sets my USER to root
. I can't add in commands using &&
or something because I would need the commands to run in the new shell instead of after that shell exits. In short, none of the commands I know of can do what I want.
The closest I was able to come was sudo -Esu user
, which makes me user
and keeps any vars I've exported. I could put something like export x=". $HOME/.bashrc"
in my .bashrc
and then eval $x
when I become user
, but that gives permissions errors, and setting +x on .bashrc
isn't sufficient because my home directory's default permissions prevent access by other users and I'm not sure I'd want to change that unless there's no other option. Not all users I'm becoming have privileges so I can't just sudo
my way in.
TL;DR: become another user while retaining my current user's aliases, functions, PS1, PROMPT_COMMAND, and vim configuration. Bash 4.2
bash sudo users su
If you want to help your users, perhaps share your .vimrc and .bashrc settings with them?
â wurtel
Aug 13 at 16:08
Meaning just shove a copy to their home directories? My settings are in flux as I learn and experiment more, and I don't want to have to remember to update it as I change it, or push it to new users as they are added. It feels like there should be a better option than making my .bashrc and .vimrc symlinks to files that everyone has at least execute access to.
â jeremysprofile
Aug 13 at 16:37
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm on a multi-user system. I have sudo b/c I'm responsible I guess. Sometimes, I want to switch to another user to help them do something, but I have a tricked-out bashrc/vimrc and I'd like to keep those.
For root, it's pretty easy. In my .bashrc
:
alias sudo='sudo '
alias -- -i='bash --rcfile $HOME/.bashrc'
export HOME="$( cd "$( dirname "$BASH_SOURCE[0]" )" >/dev/null && pwd )"
Basically, this means sudo -i
makes me root, sources my .bashrc
, and keeps my $HOME
as /home/jeremy
instead of /root
, meaning vim looks in the proper place for colors and rcfiles and things.
I want to do something similar with becoming other users. The ideal:
source my
.bashrc
; get vim to use my.vim/
stuff likevimrc
,colors/
, etc.doesn't hardcode paths -- on some systems I'm
jeremy
; on others I'mjdr
, etc.requires minimal extra typing for all of this to work by aliasing or function-ing the crap out of things.
For root, I was able to alias -i
to another command entirely that did what I wanted. man bash
doesn't list any options to do things as another user. man sudo
does, but then I wouldn't have any options to source a .bashrc
. su
seemed promising, as man su
says that su -m
preserves environment and doesn't set USER or HOME, but I'd have to sudo su -m
which sets my USER to root
. I can't add in commands using &&
or something because I would need the commands to run in the new shell instead of after that shell exits. In short, none of the commands I know of can do what I want.
The closest I was able to come was sudo -Esu user
, which makes me user
and keeps any vars I've exported. I could put something like export x=". $HOME/.bashrc"
in my .bashrc
and then eval $x
when I become user
, but that gives permissions errors, and setting +x on .bashrc
isn't sufficient because my home directory's default permissions prevent access by other users and I'm not sure I'd want to change that unless there's no other option. Not all users I'm becoming have privileges so I can't just sudo
my way in.
TL;DR: become another user while retaining my current user's aliases, functions, PS1, PROMPT_COMMAND, and vim configuration. Bash 4.2
bash sudo users su
I'm on a multi-user system. I have sudo b/c I'm responsible I guess. Sometimes, I want to switch to another user to help them do something, but I have a tricked-out bashrc/vimrc and I'd like to keep those.
For root, it's pretty easy. In my .bashrc
:
alias sudo='sudo '
alias -- -i='bash --rcfile $HOME/.bashrc'
export HOME="$( cd "$( dirname "$BASH_SOURCE[0]" )" >/dev/null && pwd )"
Basically, this means sudo -i
makes me root, sources my .bashrc
, and keeps my $HOME
as /home/jeremy
instead of /root
, meaning vim looks in the proper place for colors and rcfiles and things.
I want to do something similar with becoming other users. The ideal:
source my
.bashrc
; get vim to use my.vim/
stuff likevimrc
,colors/
, etc.doesn't hardcode paths -- on some systems I'm
jeremy
; on others I'mjdr
, etc.requires minimal extra typing for all of this to work by aliasing or function-ing the crap out of things.
For root, I was able to alias -i
to another command entirely that did what I wanted. man bash
doesn't list any options to do things as another user. man sudo
does, but then I wouldn't have any options to source a .bashrc
. su
seemed promising, as man su
says that su -m
preserves environment and doesn't set USER or HOME, but I'd have to sudo su -m
which sets my USER to root
. I can't add in commands using &&
or something because I would need the commands to run in the new shell instead of after that shell exits. In short, none of the commands I know of can do what I want.
The closest I was able to come was sudo -Esu user
, which makes me user
and keeps any vars I've exported. I could put something like export x=". $HOME/.bashrc"
in my .bashrc
and then eval $x
when I become user
, but that gives permissions errors, and setting +x on .bashrc
isn't sufficient because my home directory's default permissions prevent access by other users and I'm not sure I'd want to change that unless there's no other option. Not all users I'm becoming have privileges so I can't just sudo
my way in.
TL;DR: become another user while retaining my current user's aliases, functions, PS1, PROMPT_COMMAND, and vim configuration. Bash 4.2
bash sudo users su
bash sudo users su
asked Aug 13 at 15:45
jeremysprofile
21611
21611
If you want to help your users, perhaps share your .vimrc and .bashrc settings with them?
â wurtel
Aug 13 at 16:08
Meaning just shove a copy to their home directories? My settings are in flux as I learn and experiment more, and I don't want to have to remember to update it as I change it, or push it to new users as they are added. It feels like there should be a better option than making my .bashrc and .vimrc symlinks to files that everyone has at least execute access to.
â jeremysprofile
Aug 13 at 16:37
add a comment |Â
If you want to help your users, perhaps share your .vimrc and .bashrc settings with them?
â wurtel
Aug 13 at 16:08
Meaning just shove a copy to their home directories? My settings are in flux as I learn and experiment more, and I don't want to have to remember to update it as I change it, or push it to new users as they are added. It feels like there should be a better option than making my .bashrc and .vimrc symlinks to files that everyone has at least execute access to.
â jeremysprofile
Aug 13 at 16:37
If you want to help your users, perhaps share your .vimrc and .bashrc settings with them?
â wurtel
Aug 13 at 16:08
If you want to help your users, perhaps share your .vimrc and .bashrc settings with them?
â wurtel
Aug 13 at 16:08
Meaning just shove a copy to their home directories? My settings are in flux as I learn and experiment more, and I don't want to have to remember to update it as I change it, or push it to new users as they are added. It feels like there should be a better option than making my .bashrc and .vimrc symlinks to files that everyone has at least execute access to.
â jeremysprofile
Aug 13 at 16:37
Meaning just shove a copy to their home directories? My settings are in flux as I learn and experiment more, and I don't want to have to remember to update it as I change it, or push it to new users as they are added. It feels like there should be a better option than making my .bashrc and .vimrc symlinks to files that everyone has at least execute access to.
â jeremysprofile
Aug 13 at 16:37
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462335%2fwant-to-preserve-bashrc-and-vimrc-when-switching-to-non-root-users%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
If you want to help your users, perhaps share your .vimrc and .bashrc settings with them?
â wurtel
Aug 13 at 16:08
Meaning just shove a copy to their home directories? My settings are in flux as I learn and experiment more, and I don't want to have to remember to update it as I change it, or push it to new users as they are added. It feels like there should be a better option than making my .bashrc and .vimrc symlinks to files that everyone has at least execute access to.
â jeremysprofile
Aug 13 at 16:37