2

On my laptop

Inside ~/.ssh/config file I have this:

Host <serverAlias>
    HostName 127.0.0.1 #Server IP
    User <username>
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa

On the server

Inside ~/.bashrc I have this alias:

alias runcomman="ls -al"

What I want to do is

In my terminal I want to type ssh <serverAlias> <something> to ssh into the server & run the alias on the server.

How can I do this?

  • If bash is your login shell on the server then ssh serverAlias runcomman does find aliases from .bashrc. Is this not working? What is your login shell on the server (ssh serverAlias 'ps $$')? – Gilles 'SO- stop being evil' Nov 30 '13 at 17:49
  • This is what I got when ran the command 7493 ? Rs 0:00 ps 7493 – ahmedelgabri Dec 2 '13 at 5:45
  • Oh, your shell is optimizing tail calls (which is consistent with bash). ssh serverAlias 'ps $$'; alias, then – Gilles 'SO- stop being evil' Dec 2 '13 at 9:50
  • It listed all my "local" aliases not the server one. I want to run an alias on the server not locally, maybe I wasn't clear. – ahmedelgabri Dec 3 '13 at 5:29
2

The ".bashrc" file is only processed within "interactive shells". There are multiple question around the Stack Exchange network:

There are two options for you: modify bash settings on the server or startup your ssh command with a prefix.

  • 1
    Actually, there's an oddity in bash: it also runs .bashrc in non-interactive shells whose parent is called rshd or sshd. – Gilles 'SO- stop being evil' Nov 30 '13 at 17:47
  • 1
    I tried most of the solutions mentioned in these threads, none of them worked. – ahmedelgabri Dec 2 '13 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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