SSH配置文件别名以获取服务器上的目录 [英] SSH Config File Alias To Get To a Directory On Server

查看:163
本文介绍了SSH配置文件别名以获取服务器上的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的SSH Config文件中有一个快捷方式,它的工作原理很好,但是我要做的是将不同的Alias跳转到服务器上的不同目录。
,所以,如果我输入

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

它会连接并自动 cd 进入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/


推荐答案

在本文中 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆