linux ssh配置文件_如何在Windows终端中设置选项卡配置文件以自动SSH进入Linux盒

linux ssh配置文件

linux ssh配置文件

A lovely list of Profiles in Windows Terminal

By now I hope you've installed Windows Terminal. If not, go do that, I'll wait. It's time.

现在,我希望您已经安装了Windows Terminal 。 如果没有,那就去做,我等。 是时候了。

You may also have customize your settings. If you tried terminal a few versions ago and haven't gone back in, it's also time to let the Windows Terminal generate you a nice fresh new profiles.json (settings file). It's OK to zero-out/delete yours. Windows Terminal will regenerate it when it next starts.

您可能还自定义了设置。 如果您以前尝试过几个版本的终端机并且还没有使用过,那么现在是时候让Windows终端机为您生成一个不错的新的profiles.json(设置文件)了。 将您的内容归零/删除是可以的。 Windows Terminal下次启动时将重新生成它。

I have a number of things in my Terminal dropdown. It looks like this.

我的终端下拉列表中有很多内容。 看起来像这样。

However, I'd like to be able to have a profile that ssh's into Linux machines that I use regularly. Perhaps those remote machine can have their own cool menu item? Let's see what that would look like and how we'd do it.

但是,我希望能够拥有一个可以将ssh插入我经常使用Linux机器中的配置文件。 也许那些远程机器可以有自己的炫酷菜单项? 让我们看看会是什么样子以及我们将如何做。

向Windows终端添加新的配置文件 (Adding a New Profile to Windows Terminal)

Click the down arrow in the Windows Terminal top tab bar. Note that there are a ton of great and useful settings so explore the Settings Schema, and when you're editing the settings make sure that Visual Studio Code is set as your default handler for .json files. That's important because the Windows Terminal settings profile.json includes a JSON Schema and you'll want your settings to have autocomplete/intellisense. This will make it easier to create and discover new settings.

单击Windows终端顶部标签栏中的向下箭头。 请注意,这里有大量有用的设置,因此请探索设置架构,并在编辑设置时确保将Visual Studio Code设置为.json文件的默认处理程序。 这很重要,因为Windows终端设置profile.json包含JSON架构,并且您希望您的设置具有自动完成/智能功能。 这将使创建和发现新设置更加容易。

I'll add a profile to the "profiles" array. To start, and to learn, let's add the simplest possible profile! I'm just adding the { } as an array item in the larger profiles [] and giving it a name.

我将一个配置文件添加到“配置文件”数组中。 首先,要学习,让我们添加最简单的配置文件! 我只是在较大的配置文件[]中将{}添加为数组项,并为其命名。

"profiles": [
{
"name": "This is a name"
},

This will make a new menu item in Windows Terminal with the same name. It will have no icon and it'll launch cmd.exe as the default shell because I didn't set any other command line! It I add it at the top (as the first) item in the profiles array it'll also appear first in the menu and have the hotkey Ctrl+Shift+1.

这将在Windows Terminal中创建一个具有相同名称的新菜单项。 它没有图标,它将启动cmd.exe作为默认外壳程序,因为我没有设置任何其他命令行! 我将其添加到配置文件数组的顶部(作为第一项),它也将首先显示在菜单中,并具有热键Ctrl + Shift + 1。

This is lame, so let's add more. I'll add a tabTitle and a commandline.

这很la脚,让我们添加更多。 我将添加一个tabTitle和一个commandline

    {
"name": "This is a name",
"tabTitle": "This is a tab title",
"commandline": "powershell"
},

This menu item will appear as "This is a name" in the menu, but the the tab will be called "This is a tab title." It'll launch powershell. Note that I didn't include .exe even though I could have. I wanted to make sure you're clear that Windows Terminal is basically just called Process.Start so you can set a profile tab to call anything in the PATH, or you can be explicit. I could also add "startingDirectory" and a bunch of other options.

该菜单项在菜单中将显示为“这是名称”,但是选项卡将被称为“这是选项卡标题”。 它将启动powershell。 请注意,即使可以,我也没有包含.exe。 我想确保您清楚Windows Terminal基本上仅称为Process.Start,因此您可以设置配置文件选项卡以调用PATH中的任何内容,也可以明确。 我还可以添加“ startingDirectory ”和许多其他选项。

Since I can call anything in the PATH, what else can I get away with?

既然我可以在PATH中调用任何内容,那么我还能摆脱什么呢?

在Windows上使用OpenSSH (Using OpenSSH on Windows)

You may not have heard but OpenSSH has shipped in Windows for a few years now. That means that a lot of the utilities that you might have installed Putty for are already available in Windows. You can open an admin PowerShell and run one command to ensure OpenSSH's client apps are there:

您可能没有听说过,但Windows已经将OpenSSH交付了几年。 这意味着您可能已经安装了Putty的许多实用程序在Windows中已经可用。 您可以打开一个管理PowerShell并运行一个命令,以确保OpenSSH的客户端应用程序在那里:

Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

This installs the the client, but there's an optional server as well if you'd like.

这将安装客户端,但是如果您愿意的话,还有一个可选服务器。

I'm going to focus only on the client. Skip to the next area if you want to do your SSH'ing from Linux, not Windows.

我将只关注客户。 如果要从Linux而不是Windows进行SSH,请跳到下一个区域。

Here's what's installed in c:\windows\System32\OpenSSH

这是c:\ windows \ System32 \ OpenSSH中安装的内容

OpenSSH utilties

Here we've got sftp, scp, and most importantly, ssh.exe and ssh-agent. Since ssh is in the PATH when it's installed with Windows I can change my Windows Terminal profile to look like this and log into my Raspberry Pi 4.

这里我们有sftp,scp,最重要的是ssh.exe和ssh-agent。 由于ssh与Windows一起安装时位于PATH中,因此我可以将Windows Terminal配置文件更改为如下所示,然后登录到Raspberry Pi 4。

{
"name": "ssh hanselPi4",
"tabTitle": "HanselPi4",
"commandline": "ssh pi@hanselpi4"
},

Note in this screenshot I've got the ssh connection listed at the top, and when I click on it it opens ssh.exe and prompts me for a password. I have no ssh keys on my system that would enable auto-login, hence the password is needed.

请注意,在此屏幕快照中,我在顶部列出了ssh连接,当我单击它时,它会打开ssh.exe并提示我输入密码。 我的系统上没有可启用自动登录的ssh密钥,因此需要密码。

ssh'ing into a Raspberry Pi

从Windows终端配置文件自动SSH登录/登录Linux机器 (Automatically SSH'ing/logging into a Linux machine from a Windows Terminal profile)

Now this is important, so pay attention. If you have WSL or WSL already on your machine you can certainly just use the SSH keys and utils that are included in your preferred Linux distro.

现在这很重要,因此请注意。 如果您的计算机上已经装有WSL或WSL,则当然可以使用首选Linux发行版中包含的SSH密钥和实用程序。

In that case, your command line in your Windows Terminal profile would be something like:

在这种情况下,Windows终端配置文件中的命令行将类似于:

wsl ssh pi@hanselpi4

or if you want a specific distro, you can launch a distro and ssh from there.

或者,如果您想要特定的发行版,则可以从那里启动发行版和ssh。

wsl -d Ubuntu-18.04 ssh pi@hanselpi4

If you know Linux, then you're familiar with how to set up your public keys to allow this. However, most folks think you need Putty or some 3rd party tool to do this on Windows so I'll focus on how do to that here.

如果您了解Linux,那么您将熟悉如何设置公共密钥以允许这样做。 但是,大多数人认为您需要在Windows上使用Putty或某些第三方工具才能在Windows上执行此操作,因此在此我将重点介绍如何执行此操作。

I want to be able to type "ssh pi@hanselpi4" from my Windows machine and automatically be logged in. More specifically I want to click the profile and have it Just Work.

我希望能够从Windows计算机上键入“ ssh pi @ hanselpi4”并自动登录。更具体地说,我想单击配置文件并使其正常运行。

I will

我会

  • Make a key on my Window machine. The FROM machine, in this case, Windows. Then I want to ssh FROM here TO the remote Linux machine.

    在我的Window机器上做一个钥匙。 FROM机器,在这种情况下为Windows。 然后我要从这里SSH到远程Linux机器。
  • Tell the Linux machine (by transferring it over) about the public piece of my key and add it to a specific user's allowed_keys.

    告诉Linux机器(通过转让)有关我的密钥的公开部分,并将其添加到特定用户的allowed_keys中。

I'll run ssh-keygen to make a key from my command line on Windows. I just hit enter to generate it but you can make your own filename if you want, just use the full path and make sure you keep track of where things are. Defaults are usually best.

我将在Windows上的命令行中运行ssh-keygen来创建密钥。 我只是按Enter生成它,但是如果需要,您可以创建自己的文件名,只需使用完整路径并确保您跟踪事物的位置。 默认值通常是最好的。

>ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\scott/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in hanselpi4.
Your public key has been saved in hanselpi4.pub.

Remember the path is c:\users\yourname because that's the Windows equivalent of the ~ home folder and the keys are in c:\users\yourname\.ssh.

记住路径是c:\ users \ yourname,因为Windows相当于〜home文件夹,并且密钥在c:\ users \ yourname \ .ssh中。

Now I want to transfer what's in id_rsa.pub over to my Raspberry Pi. You can scp (secure copy) if you want, but it's best to append the key to the authorized_keys file on the destination machine.

现在,我想将id_rsa.pub中的内容转移到我的Raspberry Pi中。 您可以根据需要进行scp(安全副本)操作,但是最好将密钥附加到目标计算机上的authorized_keys文件中。

NOTE: I'm type'ing (cat on Linux is type on Windows) that text file out and piping it into SSH where I login that remote machine with the user pi and I then cat (on the Linux side now) and append >> that text to the .ssh/authorized_keys folder. The ~ folder is implied but could be added if you like.

注意:我正在键入文本文件(Linux上的猫在Windows上是键入),并将其通过管道传输到SSH中,在那里我使用pi用户登录该远程计算机,然后我用cat(现在在Linux端)并附加> >将该文本添加到.ssh / authorized_keys文件夹。 隐含〜文件夹,但可以根据需要添加。

Run this command once on Windows to output your key and pipe it over to, and append to, the right file on your remote Linux machine. You'll be prompted for your password once.

在Windows上运行一次此命令以输出密钥,并将其通过管道传输到远程Linux计算机上的正确文件,并附加到该文件。 系统将提示您输入一次密码。

type c:\users\scott\.ssh\id_rsa.pub | ssh pi@hanselpi4 'cat >> .ssh/authorized_keys'

Make sure you understand what's happening in the line above.

确保您了解上面一行中发生的事情。

添加配置文件图标-树莓派在顶部 (Adding a profile Icon - the raspberry on top)

At this point I can click the menu item in Windows Terminal and automatically be ssh'ed/logged into the remote terminal. But, scandalously, the Terminal menu item has no icon. This is clearly unacceptable M$sft sucks, right? I'll go get a nice 32x32 Raspberry Pi Icon and put it somewhere. You might put yours in a Dropbox or OneDrive so they are available everywhere you go.

此时,我可以单击Windows Terminal中的菜单项,然后自动将其登录/登录到远程终端。 但是,令人遗憾的是,“终端”菜单项没有图标。 这显然是令人无法接受的M $ sft,对吧? 我将获得一个不错的32x32 Raspberry Pi图标并将其放置在某处。 您可以将它们放在Dropbox或OneDrive中,以便随时随地使用它们。

Now my profile looks like this:

现在,我的个人资料如下所示:

"profiles": [
{
"name": "ssh hanselPi4",
"tabTitle": "HanselPi4",
"commandline": "ssh pi@hanselpi4",
"icon": "c:/users/scott/downloads/icons8-raspberry-pi-32.png"
},

How lovely is this?

这有多可爱?

A nice Raspbery Pi icon in my profile

Looks good, has a nice title and icon, and I can use a hotkey to automatically SSH into my remote machine.

看起来不错,标题和图标都不错,而且我可以使用热键自动SSH到远程计算机中。

One final note, you've already got the Azure Cloud Shell in the Windows Terminal (you can get there for free at http://shell.azure.com in your browser and access a free Linux container anywhere anytime with a persistent cloud drive) but now you can follow the instructions in this post and set up one-click SSH to anywhere.

最后一点,您已经在Windows终端中获得了Azure Cloud Shell(您可以在浏览器中通过http://shell.azure.com免费获得它,并可以通过永久性云驱动器随时随地访问免费Linux容器) ),但现在您可以按照本文中的说明进行操作,并将一键式SSH设置到任何地方。

Hope this is useful!

希望这是有用的!

翻译自: https://www.hanselman.com/blog/how-to-set-up-a-tab-profile-in-windows-terminal-to-automatically-ssh-into-a-linux-box

linux ssh配置文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值