SSH equivalent of .profile/.bashrc

bashssh

I am looking for a way to automatically define some aliases inside my session on any server I ssh to. I can't put them in the .bashrc files on the server because the user accounts I log in with are shared by other people and besides there are dozens of them and maintaining a script on every machine would be painful. I know I could use expect to type the aliases automatically but I was just wondering if OpenSSH has anything built-in that could conceivably be used to achieve this?

Best Answer

There's nothing wrong with doing it in expect. The other way that I've done it is pretty dirty too, with a script, first scp the profile you want to run, then ssh in, run it and stay connected.

So, place all the profile settings in a local file .<local username>-<hostname>-init.sh, and run the script below to log in to the remote host.

#!/bin/sh
[ $# -eq 0 ] && { echo "syntax: $0 <host> [<ssh-option>...]" 1>&2 ; exit 1 ; }
host=$1 ; shift    # use any remaining args as ssh options
initfile=".$USER-`hostname`-init.sh"
scp -q ~/.ssh-init.sh "$host:/var/tmp/$initfile"
ssh -t "$@" $host "bash --rcfile /var/tmp/$initfile"