0

I'm trying to make it ease for me by creating alias for ssh connection to my server. So I created alias in the

~/.bashrc

as follows:

alias aliasname='ssh login@ip -p 59184'

But I want to make several diffent aliases for my subfolders on the server. I tried to to something like

alias aliasname='ssh login@ip:/path/to/subfolder -p 59184'
alias aliasname='ssh login@ip/path/to/subfolder -p 59184'
alias aliasname='ssh login@ip::/path/to/subfolder -p 59184'

but always get error like Name or service not known, so clearly I do it wrong. Can someone help me here?

P.S. I should mention that regular alias to the server root works fine.

  • I don't quite get the question. What is ssh login@ip:/path/to/subfolder supposed to do? When you login through ssh, you always "land" in the home directory. Accordingly, telling ssh a destination directory is not meaningful, and thus it does not understand it. – countermode Nov 17 '16 at 11:51
  • it supposed to enter that specified directory. – lomboboo Nov 17 '16 at 11:58
  • Ok. This is not intended by default, so you have to arrange for it by yourself, see siloko's answer (which you may not only accept but also upvote). – countermode Nov 17 '16 at 12:02
2

This is the sort of thing which can and should be achieved by an ssh config file in your ~/.ssh directory. See the man pages here:

https://linux.die.net/man/5/ssh_config

EDIT: actually you can't change remote dirs in the config file, see this post:

https://stackoverflow.com/questions/14387872/ssh-config-file-alias-to-get-to-a-directory-on-server

Which basically has this in ~/.ssh/config

Host dev
  Hostname server.com
  User joe

and this in ~/.bash_profile

alias domain1 = "ssh dev -t 'cd domains/domain1; bash'"

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.