Use sudo -E
to preserve your environment:
$ export FOO=1
$ sudo -E env | grep FOO
FOO=1
That will preserve $HOME
and any other environment variables you had, so the same configuration files you started with will be accessed by the programs running as root.
You can update sudoers
to disable the env_reset
setting, which clears out all environment variables and is generally enabled by default. You may have to enable the ability to use sudo -E
at all in there as well. There are a few other sudoers
settings that might be relevant: env_keep
, which lets you specify specific variables to keep by default, and env_remove
, which declares variables to delete always. You can use sudo sudo -V
to see which variables are/are not preserved.
An alternative, if you can't modify sudoers
, is to provide your environment explicitly:
sudo env HOME=$HOME command here
You can make a shell alias to do that automatically so you don't have to type it in.
Note that doing this (either way) can have potentially unwanted side effects: if the program you run tries to make files in your home directory, for example, those files will be created as root and your ordinary user won't be able to write to them.
For the specific case of vim
, you could also put your .vimrc
as the system-wide /etc/vimrc
if you're the only user of this system.
Assuming your username is testssh
:
- create
/etc/ssh/authorized_keys_testssh
and put your key there
- add the following in
/etc/ssh/sshd_config
:
Match User testssh
AuthorizedKeysFile /etc/ssh/authorized_keys_%u
and restart sshd. Your user will be able to ssh with his private key.
Best Answer
POSIX
Searching through the specification for the strings "user config" or "configuration files" turned up zero hits, so I would say no it doesn't specify this in any way.
FHS
Looking at the FHS - Filesystem Hierarchy Standard it had this bit:
sysconf/getconf
Looking through the list of POSIX configuration constants present in
<limits.h>
is the only other place I can think of where something like this would be configured. Running the commandgetconf <var>
will return these types of results.For example:
But looking through the list of definitions I don't see any pertaining to a user's home directory.