0

I need to keep ssh'ing into many-different Linux boxes (Ubuntu mostly) and every time I miss my basic aliases. Is there a way to setup aliases etc

  • while opening an interactive ssh a machine
  • without tinkering with remote machines's .bashrc/.bash_profile?

Following would just execute the alias commands in a non-interactive shell on remote machine and terminate the session (as expected): kashyap@Laptop$ ssh [email protected] "alias c=clear; alias p=pwd; alias l='ls -altr'

I would love it if I could select a file from local machine to be executed as init script on remote, but willing to settle for less.

E.g.

ssh usr@remote --init-script=/local/my_init_script_for_ssh_sessions
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Kashyap
  • 183
  • 1
  • 6

1 Answers1

-1

You can achieve this by adding

LocalCommand scp username@yourserver:~/.bashrc /serverhome/.bashrc;source .bashrc

line to your ssh config file. There is also a PermitLocalCommand option that needs to be set to true.

PoX
  • 296
  • 2
  • 9
  • `LocalCommand` doesn't have access to the session and is run locally. – RealSkeptic Apr 11 '16 at 20:39
  • Thats the idea it will scp file and source bashrc on session initiate – PoX Apr 11 '16 at 20:41
  • It is going to execute **locally**, on the machine where you run `ssh`, not on the machine where you run `sshd`. Try using `hostname` as your `LocalCommand` and see on which host in executes. – RealSkeptic Apr 11 '16 at 20:50
  • This can work partially if You have the host configured in .ssh/config and replace the username with %r, yourserver with %h. But then the source .bashrc won't reload the before created session. – Thomas Nov 09 '16 at 11:40