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?
|
|
|||
|
|
|
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
|
||||
|
|
You could put your configuration in
(untested, but should do) |
|||||||
|
|
From the ssh(1) man page, if you create a file ~/.ssh/rc, it will be executed BEFORE the user's login shell is executed, thereby giving the chance to do 'pre-setup' tasks before logging in... the example given was to mount network shares before logging in. If you don't want to use individual ~/.ssh/rc files, you can do the same with /etc/ssh/sshrc. A quick test to check for your particular username or some identifyiing method could restrict others from even noticing this was in place. /etc/ssh/sshrc is ONLY sourced if ~/.ssh/rc does not exist, so you can effectively achieve two layers of complexity. |
|||||||
|
|
Aliases are defined and interpreted by the shell. Unfortunately there's no way for You could write an |
|||
|
|
|
If possible, I would store a small script that initialize/define everything you want on a server accessible from everywhere and execute it after login in each server. |
|||
|
|
|
One possible solution would be to put your script that sets everything up on a webserver that all the other servers can access. Then each server should just need a small script to do something like:
That way you only have to update it in one place. |
|||
|
|
|
Look at .ssh/config Here is a example https://lookherefirst.wordpress.com/2007/12/17/a-simple-ssh-config-file/ |
|||||
|