ssh 配置文件别名_使用您的SSH配置文件为主机创建别名

ssh 配置文件别名

ssh 配置文件别名

banner-01

This trick is for Linux and SSH users who often log in to remote systems. Having to type the same info over and over again is mind-numbingly repetitive, but using an SSH config file makes the process much more convenient.

该技巧适用于经常登录到远程系统的Linux和SSH用户。 一次又一次地重复输入相同的信息非常麻烦,但是使用SSH配置文件使此过程更加方便。

It’s pretty easy to turn

转动起来很容易

scp –P 50001 username@remote.sshserver.com:somefile ./somefile

scp –P 50001 username@remote.sshserver.com:somefile ./somefile

ssh –p 50001 username@remote.sshserver.com

ssh –p 50001 username@remote.sshserver.com

into something quick:

快速的东西:

scp remotehost:somefile ./somefile

scp remotehost:somefile ./somefile

ssh remotehost

SSH远程主机

Aside from specifying port numbers, addresses, and user names, you can specify key files, time out intervals, and tons of other options. All it takes is one little file.

除了指定端口号,地址和用户名之外,您还可以指定密钥文件,超时间隔和大量其他选项。 它所需要的只是一个小文件。

Fire up a text editor and point it to this file:

启动文本编辑器并将其指向此文件:

~/.ssh/config

〜/ .ssh / config

Alternatively, you could put the contents and save it to that file, but it’s best to make sure to open it if it already exists. Here’s the basic format of what you need to put (or add to what you have).

或者,您可以放置​​内容并将其保存到该文件,但是最好确保将其打开(如果已存在)。 这是您需要放入(或添加到所拥有内容)的基本格式。

config file

Replace “your_alias_name” with a short name for this connection. Something like “home,” “work,” or “asdf” should suffice. ;-)

用此连接的短名称替换“ your_alias_name”。 像“家”,“工作”或“ asdf”之类的东西就足够了。 ;-)

Substitute your username, and the web address (or IP address for destinations inside of your network) instead of remote.sshserver.com. Lastly, if you use a custom port (anything other than 22, the default), specify that. Otherwise, you can skip that last line.

替换您的用户名和Web地址(或网络内部目标的IP地址),而不是remote.sshserver.com。 最后,如果您使用自定义端口(默认端口不是22),请指定该端口。 否则,您可以跳过最后一行。

Next, I created a pair of key files on my remote server to use, so I didn’t have to supply a password each time. For more information, check out How To Remotely Copy Files Over SSH Without Entering Your Password and skip down to the “SSH and SCP Without Passwords” section for all of the details.

接下来,我在远程服务器上创建了一对密钥文件以供使用,因此不必每次都提供密码。 有关更多信息,请查看如何在不输入密码的情况通过SSH远程复制文件,并跳至“没有密码的SSH和SCP”部分以获取所有详细信息。

key pairs

Now, you can add an extra line and point it to your key file.

现在,您可以添加额外的一行并将其指向您的密钥文件。

IdentityFile ~/path/to/id_file

IdentityFile〜/路径/到/ id_file

id file

Let’s add a “keep alive” function to our connect, shall we? This will prevent your connection from ending by refreshing your connection every X seconds, a maximum number of Y times:

让我们在连接中添加一个“保持活动”功能,对吗? 通过每X秒刷新一次连接(最多Y次)来防止连接结束。

ServerAliveInterval X

ServerAliveInterval X

ServerAliveCountMax Y

ServerAliveCountMax Y

alive int

Our example will refresh every 2 minutes for a maximum of 30 consecutive times. That means, it will stop refreshing after an hour. This works from your client regardless of what your server has configured.

我们的示例每2分钟刷新一次,最多连续30次。 这意味着一个小时后它将停止刷新。 无论您的服务器配置了什么,它都可以从客户端运行。

You can add multiple servers this way by adding another section with a difference Host section. And, if you want to create a set of default options, you can set the Host value to a single asterisk (*). Here’s a great example file:

您可以通过添加另一个具有不同“主机”部分的部分来以这种方式添加多台服务器。 并且,如果要创建一组默认选项,则可以将“主机”值设置为单个星号(*)。 这是一个很棒的示例文件:

final
sshot-1

Much better!

好多了!

This is handy for situations when creating a bash alias isn’t an option. It also makes it easier to keep track of all of your SSH-based options (from the client-side) in one consolidated place. If you plan to use this for scripts, you can also use

对于无法创建bash别名的情况,这非常方便。 它还使在一个合并的位置中更轻松地跟踪所有基于SSH的选项(从客户端)。 如果您打算将其用于脚本,也可以使用

BatchMode yes

BatchMode是

to disable prompts to enter passwords. Of course, you’d still need to authenticate using key files.

禁用提示输入密码的提示。 当然,您仍然需要使用密钥文件进行身份验证

If you want to look more into the StrictHostKeyChecking option, be sure to Learn the Ins and Outs of OpenSSH on Your Linux PC. Of course, there’s a cornucopia of options available to you in the OpenSSH man page, too.

如果您想更多地了解 StrictHostKeyChecking选项,请确保了解Linux PC上OpenSSH的来龙去脉。 当然,在OpenSSH手册页中也可以找到很多选项。

翻译自: https://www.howtogeek.com/75007/stupid-geek-tricks-use-your-ssh-config-file-to-create-aliases-for-hosts/

ssh 配置文件别名

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值