SSH Config File Alias To Get To a Directory On Server [closed]

徘徊边缘 提交于 2019-12-03 07:58:28

问题


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/

回答1:


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.




回答2:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!