2

I've got a bunch of good stuff in my bash config. Normally when I get a new account, I pull this down from my GitHub repo so that I have all the aliases and features I'm used to. There are some hosts that I access which I don't have my own accounts on, but shared accounts that a bunch of people use, so it would be rude of me to install my shell config.

Is there a way to push my shell config, or at least some initialization commands, over the SSH session so that I have the environment I'm used to?

Drew Stephens
  • 662
  • 7
  • 12

3 Answers3

1

I like to keep a file .bsa somewhere convenient (maybe ~ will work in this case) so I can just . ~/.bsa to get my environment.

geekosaur
  • 7,025
  • 1
  • 19
  • 19
1

Insert obligatory grumble about shared accounts, but if you at least have your own ssh key, you can (ab)use the command= option in the ~/.ssh/authorized_keys file. A key with a command option is good only for running the specified command; but the command in the authorized_keys file runs with the environment variable SSH_ORIGINAL_COMMAND set to the command the user specified (empty for interactive sessions). So you can use something like this in ~/.ssh/authorized_keys:

command="HOME=$HOME/.HOME.drew;
         if [ -n \"$SSH_ORIGINAL_COMMAND\" ]; then
           eval \"$SSH_ORIGINAL_COMMAND\";
         else exec \"$SHELL\"; fi" ssh-rsa AAAA…== drew@example.com

Note that I put line breaks above for legibility, but this actually needs to be all on one line in the authorized_keys file.

Then put your favorite configuration files in that .HOME.drew directory.

For punctual use, you can explicitly source a profile file or run any shell command. Pass the -t option to have a terminal if you want to run interactive commands.

ssh shared-account@server "LS_COLORS='$LS_COLORS' ls --color"
ssh -t shared-account@server '. ~/.profile.drew; exec zsh'

If you only want to edit or copy files on the remote machine, you can use a network filesystem such as SSHFS (for unix clients) or Tramp (for Emacs) and work from the comfort of your local environment.

0

Maybe try to hack something together with "LocalCommand" (see man ssh_config)?

DictatorBob
  • 1,614
  • 11
  • 15