1

I need to create some aliases on remote Ubuntu and enable them on ssh-connection. So I defined aliases in ~/.bashrc file (on that remote Ubuntu).

Now when I do

ssh root@<Remote IP>
source ~/.bashrc

I can use those aliases... But instead of do source ~/.bashrc manually each time I want to automate that as well. So I tried

sshpass -p 'none' ssh -o StrictHostKeyChecking=no root@<Remote IP> -t 'source ~/.bashrc'

... but the connection is closed

if I do

sshpass -p none ssh -o StrictHostKeyChecking=no root@<Remote IP> -t 'ssh root@<Remote IP>; source ~/.bashrc'

then it's not disconnected, but no possibility to input commands - no reaction from terminal on input

So how to connect to remote host and load ~/.bashrc in the same command?

JaSON
  • 133

1 Answers1

5

When you do ssh root@<Remote IP>, you will get root's login shell which (assuming it's bash) will load /root/.profile (or /root/.bash_profile if it exists).

So probably the cleanest solution is to make sure that file sources the .bashrc file (giving root's login shell the same environment as their non-login interactive shell).

The default Ubuntu ~/.profile (copied from /etc/skel/) does this automatically:

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi
steeldriver
  • 142,475