using separate environments for people using single account

there is this situation: multiple people have to have access to single system account on unix/linux.

you are one of them, but you really want to have your own environment. aliases, path, and so on.

problem? others dont want your changes. is it a lost case?

luckily – no.

first, i need to assume you're logging to this account/machine using ssh.

what's important – sshd has to be configured to allow user environments. this is done by modification of /etc/ssh/sshd_config, and adding there this line:

PermitUserEnvironment yes

(after addition you have to restart sshd)

now, we will need to use ssh-key authentication, but this is usually no-brainer as password based authentication is not really as featurefull as key-based way.

so, having key based authentication, you have this file: ~/.ssh/authorized_keys. which looks more or less like this:

ssh-rsa AAAAB3NzaC1yc2EAAAAB...
ssh-dss AAAAB3NzaC1kc3MAAACB...

each line is one key, associated with one user.

now, let's modify the line that belongs to me. in this case, this is the first one.

let's add there:

environment="SSH_USER=depesz"

after this modification authorized_keys will look like this:

environment="SSH_USER=depesz" ssh-rsa AAAAB3NzaC1yc2EAAAAB...
ssh-dss AAAAB3NzaC1kc3MAAACB...

so, let's test if it works:

=> ssh test@test
Last login: Sat Mar 29 22:20:26 2008 from xxx
=> echo $SSH_USER
depesz

great. so i have the environment set. what can i do about it? that's rather simple. at the end of ~/.bashrc (or ~/.bash_profile, or anything else that you're using) add:

test -f "$HOME/.bashrc-$SSH_USER" && source "$HOME/.bashrc-$SSH_USER"

(or similar based on your preference).

then in ~/.bashrc-depesz you can set anything you want: aliases, paths, environment variables – anything you want, and it will be set only for your own ssh connections. quite nifty.