4

I have my bashrc file set up to my liking.I usually work on a hardware that is plugged into a remote server.I ssh into that remote server.I would like my .bashrc to be run when I ssh into the remote server,instead of the bashrc on the server.Is there anyway by which I can accomplish this.?

liv2hak
  • 303
  • 4
  • 13
  • 25
  • Similar question at https://serverfault.com/questions/400522/how-to-use-a-custom-bashrc-file-on-ssh-login – Lætitia Nov 30 '22 at 14:32

3 Answers3

2

AFAIK, there is no way to do that.

Maybe you should copy your ~/.bashrc to a server and install a configuration management tool (Puppet, Chef, ...) on all the other servers to pull it.

quanta
  • 51,413
  • 19
  • 159
  • 217
  • Another suggestion for the same problem.I could write a bash function which does ssh to the remote machine,does an scp of ~/.bashrc to a folder on the remote machine and does a bash with that bashrc as the parameter. – liv2hak Aug 16 '11 at 00:58
  • While working with Puppet, Chef, etc, will set the OP on the right path, it seems a bit overkill for simply having .bashrc updated. – gtirloni Sep 12 '14 at 18:03
2

I think sshrc is what you're looking for: https://github.com/taylorskalyo/sshrc

sshrc works just like ssh, but it also sources ~/.sshrc after logging in remotely.

$ echo "echo welcome" > ~/.sshrc
$ sshrc me@myserver
welcome

$ echo "alias ..='cd ..'" > ~/.sshrc
$ sshrc me@myserver
$ type ..
.. is aliased to `cd ..'

You can use this to set environment variables, define functions, and run post-login commands. It's that simple, and it won't impact other users on the server - even if they use sshrc too. For more advanced configuration, continue reading.

Lætitia
  • 2,085
  • 22
  • 33
RussellStewart
  • 287
  • 2
  • 3
0

I think that https://github.com/fsquillace/pearl-ssh does what you need.

I wrote it long time ago before sshrc was born and it has more benefits compared to sshrc:

  • It does not require dependencies on xxd for both hosts (which can be unavailable on remote host)
  • Pearl-ssh uses a more efficient encoding algorithm
  • It is just ~20 lines of code (really easy to understand!)

For instance:

$> echo "alias q=exit" > ~/.config/pearl/sshrc
$> ssh_pearl [email protected]
myserver.com $> q
exit
user967489
  • 111
  • 1
  • 3