0

This question already has an answer here:

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 root@ec2-1-2-3-4.compute-6.amazonaws.com "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

marked as duplicate by Gilles ssh Apr 11 '16 at 23:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

-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.

  • 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. – fane89 Nov 9 '16 at 11:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.