SSH 客户端的快捷方式

vic*_*ico 11 ssh command-line

我有很多需要登录的远程机器。我需要以某种方式存储连接参数,因为手动输入它们太无聊了。我也更喜欢在这些快捷方式中存储密码。在 Windows 下运行的类似 MTPuTTY 的软件将解决我在 Ubuntu 中的问题。

如何解决这个问题呢?

小智 15

您可以使用.ssh/config文件做很多事情。它可以让你替换这个:

ssh fooey@dev.example.com -p 22000
Run Code Online (Sandbox Code Playgroud)

和:

ssh dev
Run Code Online (Sandbox Code Playgroud)

为此,您必须在末尾添加以下几行.ssh/config(如果不存在则创建它)

Host dev
    HostName dev.example.com
    Port 22000
    User fooey
Run Code Online (Sandbox Code Playgroud)

关于凭据的存储,我强烈建议您使用密钥身份验证而不是基于密码的身份验证。您可以使用 GUI 或终端创建它们。

图形用户界面

打开Seahorse,选择File > New,然后Secure Shell Key让界面引导您

终端 创建您的 RSA 密钥对:

ssh-keygen -t rsa
Run Code Online (Sandbox Code Playgroud)

存储密钥和密码:

Enter file in which to save the key (/home/demo/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Run Code Online (Sandbox Code Playgroud)

复制公钥

ssh-copy-id fooey@dev.example.com
Run Code Online (Sandbox Code Playgroud)

资料来源:


inf*_*xed 5

如果您愿意,您可以制作简短的 shell 脚本来启动您的 ssh 会话,然后将它们作为 s 可执行文件 ( chmod o+x) 执行,或者使用 dot.命令

像制作文件 ~/ssh2hostA.sh

#!/bin/sh
sshpass -p 'yourpassword' ssh user@hostA
Run Code Online (Sandbox Code Playgroud)

然后开始

. ~/ssh2hostA.sh

这不是一件好事,因为您不仅在文件中散布着明文密码,而且人们可能能够在w命令中看到密码。( 和top, 和/proc)

真的,您应该为此使用 ssh 主机密钥。

真的。