I have a shortcut in my SSH Config file and it works great, but what I want to do is have different Aliases jump to different directories on the server. so if I type
ssh domain1
It connects and will automatically cd into domain1's directory.
Is there a way to do that? Something like
Host dev1
Hostname example.com
User myname
Dir domains/domain1/
Host dev2
Hostname example.com
User myname
Dir domains/domain2/
In this post on ServerFault, they say you can't do it all through the ssh config file. But you can do it with the ssh config and your .bash_profile or whatever the terminal nerds call it. in the ssh config file add
Host dev
Hostname server.com
User joe
then in your .bash_profile add an alias
alias domain1="ssh dev -t 'cd domains/domain1; bash'"
Here the dev refers to what you set up in the config file.
In the Terminal, just type domain1, you will be asked to put in your password and will go straight to the directory. Make a new alias for all your domains and it will make logging in to each one super easy.
Take a look at https://serverfault.com/questions/167416/change-directory-automatically-on-ssh-login
This is the accepted answer:
What you're looking to do can't really be accomplished via SSH; you need to modify the shell in some way, e.g. via bashrc/bash_profile.
Just for the sake of completeness, you can ssh -t to change the directory (I know that was not your question, but it may help others):
ssh server -t "cd /my/remote/directory; bash --login"
来源:https://stackoverflow.com/questions/14387872/ssh-config-file-alias-to-get-to-a-directory-on-server