SSH配置文件段落以在远程服务器上打开特定目录 [英] SSH config file paragraph to open a specific directory on remote server
问题描述
是否有一种方法可以专门将SSH远程放置到特定目录中,专门使用本地ssh配置文件(不是终端)?例如,以下段落中的 Dir
选项类似,
Is there a way to specifically ssh into a particular directory in remote location, specifically using the local ssh config file (not terminal)? Something like Dir
option in the paragraph below, for example,
Host remote_dir
Hostname remote_server
User username
Dir path/to/remote_dir/
因此,如果我, ssh使用上一段中的Host值,
So, if I, ssh using the Host value from above paragraph,
ssh remote_dir
然后,我想登录,终端可以在 path / to / remote_dir /
为我准备好
Then, I would like to be logged in and the terminal to be ready for me at path/to/remote_dir/
of the remote server,
username@remote_server: path/to/remote_dir/ > pwd
/home/username/path/to/remote_dir/
推荐答案
在此帖子在ServerFault上,他们说可以通过ssh配置文件完成所有操作。但是您可以使用ssh配置和.bash_profile或终端书呆子称呼它的任何方式来执行此操作。 ssh配置文件中的
添加
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
然后在.bash_profile中添加别名
then in your .bash_profile add an alias
alias domain1="ssh dev -t 'cd domains/domain1; bash'"
此处 dev
是指您在配置文件中设置的内容。
Here the dev
refers to what you set up in the config file.
在在终端上,只需键入 domain1
,系统将要求您输入密码,然后直接进入目录。为您所有的域创建一个新的别名,它将使登录每个域变得非常容易。
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.
这篇关于SSH配置文件段落以在远程服务器上打开特定目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!