bash 来自 Windows 桌面的 cygwin ssh 快捷方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12206190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:08:57  来源:igfitidea点击:

cygwin ssh shortcut from windows desktop

bashwindows-7sshcygwin

提问by ivan_drago

I have multiple servers that I need to remote into. I prefer Cygwin over Putty to do so.

我有多个需要远程访问的服务器。我更喜欢 Cygwin 而不是 Putty 这样做。

Anyhows - the process of opening my cool Mintty window and then typing the following commands takes too long. PS - I am using a "key" authentication to these servers.

无论如何 - 打开我很酷的 Mintty 窗口然后输入以下命令的过程需要很长时间。PS - 我对这些服务器使用“密钥”身份验证。

First, I double Click Cygwin Terminal shortcut from my windows desktop.

首先,我从 Windows 桌面双击 Cygwin Terminal 快捷方式。

Then once the terminal session has booted up, from the command prompt I type the following -

然后一旦终端会话启动,我从命令提示符输入以下内容 -

$ eval `ssh-agent`
$ ssh-add
$ ssh <username>@<servername>

Please keep in mind that my 'servername' is variable. In fact I have about 10 different server names that could potentially be inserted there - Hence my need for 10 different shortcuts. I would prefer to double click on something from my desktop that will fire up my Mintty and automatically execute the above bash shell commands.

请记住,我的“服务器名”是可变的。事实上,我有大约 10 个不同的服务器名称可以插入那里 - 因此我需要 10 个不同的快捷方式。我更喜欢双击桌面上的一些东西,它会启动我的 Mintty 并自动执行上面的 bash shell 命令。

Does anyone have or can recommend a nice/elegant solution to do this?

有没有人有或可以推荐一个漂亮/优雅的解决方案来做到这一点?

(I have a feeling that it has something to do with the Target attribute of the Windows short-cut icon that I am clicking on.)

(我有一种感觉,它与我单击的 Windows 快捷图标的 Target 属性有关。)

采纳答案by ivan_drago

To accomplish this I did the following steps:

为此,我执行了以下步骤:

Step 1: Created a directory where I installed Cygwin called scripts

第 1 步:创建一个目录,我在其中安装了 Cygwin,称为脚本

Step 2: In this directory created a BASH script called servername.sh

第 2 步:在此目录中创建一个名为 servername.sh 的 BASH 脚本

Step 3: servername.sh will have the following contents (a single line):

第三步:servername.sh 将包含以下内容(单行):

eval `ssh-agent`;ssh-add;ssh user@servername

(Make sure you substitute user and servername with the appropriate information)

(确保用适当的信息替换用户名和服务器名)

Step 4: Created a shortcut of your Cygwin Terminal icon

第 4 步:创建 Cygwin 终端图标的快捷方式

Step 5: Pasted it where I wanted it (on my Desktop - but you can chose where you want to place it).

第 5 步:将其粘贴到我想要的位置(在我的桌面上 - 但您可以选择要放置的位置)。

Step 6: Right click and renamed my shortcut (name it my server name)

第 6 步:右键单击并重命名我的快捷方式(将其命名为我的服务器名称)

Step 7: Right click and select Properties

第 7 步:右键单击并选择“属性”

Step 8: In the Target attributes section I have the following line of code -

第 8 步:在目标属性部分,我有以下代码行 -

C:\Cygwin\bin\mintty.exe -e /bin/sh -l -c '/scripts/servername.sh'

And make sure your paths match up with your environment!

并确保您的路径与您的环境相匹配!

Cheers.

干杯。

回答by me_and

You can do this without too much difficulty. Copy the existing Cygwin Terminal icon, right click on it, and select Properties. You should see something like the below in the Target field:

你可以毫不费力地做到这一点。复制现有的 Cygwin 终端图标,右键单击它,然后选择属性。您应该在“目标”字段中看到如下所示的内容:

C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -

Replace this with the following (replacing <username>and <servername>as relevant):

将其替换为以下内容(替换<username><servername>相关):

C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico /bin/bash -l -c "eval `ssh-agent` ; ssh-add ; ssh <username>@<servername>"

Repeat as necessary for your other servers. That's it!

根据需要对其他服务器重复此操作。就是这样!

(Detail: We replace the -argument [which means to use the standard login shell] with an explicit call to bash to run your commands. The -lpart means to use a login shell, which in particular means your PATHvariable is set up and so bash can find ssh. The -cpart just introduces the command, which you should recognize from your question.)

(详细信息:我们用-显式调用 bash替换参数 [表示使用标准登录 shell] 以运行您的命令。这-l部分表示使用登录 shell,这特别意味着您的PATH变量已设置,因此 bash 可以find ssh。这-c部分只是介绍了命令,您应该从您的问题中识别出来。)