The new Windows terminal was released back in June of 2019 and has brought several exciting and modern features such as support for tabs, availability for in-depth styling, as well as a configurable JSON file to the Windows Command Line environment. These components together offer the terminal user an endless array of configurations, making this a valuable tool for development work and system administration. It also lends itself to creativity and finding the best fit for the type of work you find yourself doing at the command line.
If you do not already have the new Windows Terminal installed, this article from Microsoft will get you up and running.
Expanded Profile Support
One of the most exciting features to me is the Windows Terminal’s support for profiles. These profiles make up the different command line environments on your machine and, by default, include Windows Powershell, Command Prompt and the Azure Cloud Shell. If you also have a Windows Subsystem for Linux Distribution installed, that shell will automatically be loaded into one of your Windows Terminal profiles. The nice thing about support for different profiles is that we can create and edit them as we wish. In this tutorial, I’ll be diving into configuring a profile for connecting to SSH servers from the new Windows Terminal. Then I’ll continue on to show you to how to tie this together with SSH Keypairs.
Prerequisites
- Valid SSH User Account and Credentials for the SSH server
- Windows Terminal installed
- OpenSSH enabled on Windows 10
- SSH Server with Public Key Authentication allowed (optional)
To begin, we will start by opening our settings.json file within your favorite text editor and creating a new profile within the profiles list for our SSH connection.
Getting Started
The settings.json file is accessible within Windows Terminal by pressing CTRL + , or by navigating to the drop-down arrow and selecting Settings. Once open, you will see that the profiles array is made up of several different properties. You can find the full list here:
Out of simplicity, I will create my new entry at the bottom of the list and add a comma to the closing brace of the above profile. Use the below code to add a new profile for our SSH connection:
{ "guid": "{5063f744-37f9-4c7c-aba5-51fa0789ee1a}", //Random GUID "hidden": false, //Show the profile in the dropdown "name": "server1", //Name of profile "commandline": "ssh bob@server1" //Program, replace user/host }
Notes on Properties
Each profile you add will need a unique random guid property. You can choose the name that you would like to show within the drop-down menu with the name property. The commandline property allows the user to supply the name of the executable used when the profile is launched.
Looking at the default options, we can see that the commandline property calls executables like powershell.exe and cmd.exe. Applying this same idea, we can begin to create the profile using the SSH executable then apply some basic SSH concepts to fully automate our login process. Make sure to substitute your username and hostname or IP Address within the profile.
Now what?
At this point, we have a functioning profile that launches the SSH executable and connects to the server with the username provided, but it still requires a password. This works perfectly fine, but wouldn’t it be nice to open this profile with a keyboard shortcut then have the SSH executable utilize an SSH Keypair to provide passwordless authentication to the server?
Setting up the SSH Client for Public Key Authentication
We will begin this process by creating a new SSH keypair to use with this server. You can skip this step if you already have a keypair you utilize for the server you are connecting to.
I will utilize OpenSSH’s built-in functionality for generating private keypairs, ssh-keygen. To do this, I will run ssh-keygen then specify a name for the keypair after being prompted and, finally, provide the key a secure passphrase for added security. You should always set passphrases for your keypairs in case they end up in the wrong hands somehow. For more in-depth information on ssh-keygen’s functionality and security, check out the manual page.
The input will be the following:
ssh-keygen # Generate your new SSH keypair # Give it a name and a passphrase
Here’s an example output:
Moving Your Public Key to the SSH Server
Once we have our keypair created, it will by default appear within your C:\Users\$ENV:USERNAME\.ssh\ folder with the public key appended with .pub and the private key appearing as the name you associated with the keypair. Now, we must move our public key over to the authorized_keys file within your respective /home/.ssh/ directory on the server. There is a multitude of ways to do this, but out of simplicity and the lack of a tool like ssh-copy-id on Windows, we will utilize another piece of OpenSSH’s suite—SCP—to move our file itself to the server. Only move your public key; the private key should never be copied to other machines.
I will move my public key over to my home folder (~) on the SSH server using the following SCP command. You will be prompted to log in with your SSH credentials:
scp C:\Users\$ENV:USERNAME\.ssh\yourpublickey.pub user@ipadddress:~ #Replace user@ipaddress with your user and IP
Now that we have our public key on the server, we can copy and paste it into our authorized_keys file to allow password-less login using this keypair. SSH into the server using your username and password. Next, copy the contents of the public key, and authorize it by adding it to the authorized_keys file within your /home/.ssh/ directory:
#Read out your public key and copy the output cat yourpublickey.pub #Open your authorized_keys file in vim sudo vim ~/.ssh/authorized_keys #Paste the copied output within the authorized_keys file, right click within vim to paste the contents.
Once you are within vim (or your preferred UNIX text editor), follow these steps:
- Enter insert mode by pressing (i)
- Navigate to a new line if you have additional SSH Keys
- Right-click to paste the contents of the public key
- Press Esc + :wq! to save and exit the file
Note: Feel free to remove your public key from your home directory with the rm command. We will not be using that Public Key any longer since we have configured it as an authorized key already.
Tying It All Together
That is it! We can confirm that password-less login is working by opening our profile we made earlier from the Windows Terminal drop-down menu. Let’s give that a go:
Great! It works! We were prompted for our SSH key passphrase and granted password-less login via our profile we created in the Windows Terminal application. If you manage multiple servers with multiple keypairs, I would recommend looking into creating an SSH configuration file. This configuration file would automatically apply your preconfigured settings to each host you connect to. Learn more about SSH configuration files.
To recap, in this tutorial we covered creating an SSH profile within the new Windows Terminal then configuring this profile for password-less authentication using a private keypair. This setup gives some serious management capability for anyone who works at the terminal on multiple systems concurrently. I hope you found this tutorial helpful in configuring your terminal, and don’t forget to dig into the other cool things the new Windows Terminal has to offer like keyboard shortcuts, color schemes and pane splitting. Check out their full documentation, and feel free to reach out to us at InterWorks if we can help you in your exploration.
Wiindows terminal is proving to be an awesome tool for terminal(CLI) lovers. With its cusomization capabilities the possibilities are endless. Here in this article I’m going to explore connecting to a remote Linux server using SSH and private key using Windows Terminal.
Prerequisite to this tutorial is that you need to have Windows Terminal installed on your Windows computer. (That can be easily done from the Windows Store)
What is the default option?
Till now if you wanted to ssh into a remote computer you’d have to:
- Open Windows Powershell or Command Prompt.
- Type in
ssh user@REMOTE-IP-ADDRESS-OR-FQDN
- Enter user password
Everytime you want to start a new ssh session. Not anymore.
Step 1: Create a public/private rsa key pair.
Open Command Prompt/Powershell or as I like it, Powershell in Windows Terminal. Type in ssh-keygen -t rsa
. It’ll ask, in which file (or where) to save the key. I’d suggest you go with the default option i.e. C:\Users\<username>/.ssh/id_rsa
Press Enter
without typing in anything.
Now it’ll ask you to enter a passphrase. This is an optional step, if multiple users access your computer then it is a nice thing to do but, if you are the only one accessing then there’s no need. Just hit the Enter key «twice».
Step 2: Copy the public key into the remote system.
Usually if you’re on a linux pc it is as simple as this command ssh-copy-id <user>@REMOTE-IP-ADDRESS-OR-FQDN
. But ssh-copy-id is not available on Windows, hence, the following command.
cat ~/.ssh/id_rsa.pub | ssh user@REMOTE-IP-ADDRESS-OR-FQDN "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"
In my case it looks something like this
cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"
After executing the above command it’ll ask for the user password for the remote computer. Enter your password and you’re done copying your public key into the remote computer.
Step 3: Setup Windows Terminal to connect in one click.
Open Windows Terminal (if not already open). Then click on the down arrow next to the Pwershell tab and then Settings
.
This will open the Settings
pane, and on the bottom left you’ll see an option to Open JSON
, click on it to open the settings.json
file. You can use any editor to open the file. My poison is VSCode.
Scroll down to "profiles"
and copy and paste (don’t forget to change to your user and ip address) the following inside the "list"
array, as shown in the screenshot below.
{
"guid": "{0caa0dad-35be-5f56-a8ff-afceaeaa6103}",
"name": "Home Server",
"commandline": "ssh -i \"~/.ssh/id_rsa\" user@REMOTE-IP-ADDRESS-OR-FQDN",
"hidden": false
},
Save the settings.json
file and click the same down arrow on the Windows Terminal and you’ll see your entry in the drop down list.
Select it and Boom! you’re connected to the remote system in just One Click!
Until next time Ciao
.
- Windows Terminal
- ssh
- private key
- vscode
I have not used Linux very much since running Ubuntu almost 15 years ago. Now I have some Raspberry Pi and recently converted my virtual machine host to Ubuntu. So I have been using SSH a lot more, and I want to make it easier to SSH into my growing litter of Linux boxes.
This guide is mostly instructions for future me when I inevitably forget them or pave over my machine again.
For the examples, I’ll be using the username user
and the machine reliablechair
, which is on the network at reliablechair.lan
.
Install OpenSSH
OpenSSH is offered as a Windows feature, but I prefer to install it with Chocolatey.
Run the following commands in an elevated PowerShell console.
choco install openssh
cd 'C:\Program Files\OpenSSH-Win64\'
Set-Service -Name ssh-agent -StartupType Automatic
Start-Service ssh-agent
Create an SSH key
The next step is to create an SSH key. I am making one for each target machine, which is probably not necessary. You can use the same key for multiple machines if desired. In that case, you can leave off the filename and use the default name provided by ssh-keygen
.
You can choose to use a passphrase to secure the key or not. If you do, you will have to enter the passphrase at some point before SSHing into the machine.
These commands do not need an elevated console.
cd ~
ssh-keygen -t rsa -b 4096 -f .\.ssh\reliablechair
Add an initial entry to SSH config
This entry will let us connect to reliablechair with a password while copy the public key over. Without setting this up, you could get connection errors if SSH tries to use other SSH keys on your machine.
With this entry, using ssh reliablechair
will be the same as ssh user@reliablechair.lan
.
Host reliablechair
User user
HostName reliablechair.lan
PreferredAuthentications password
Copy the public key to the target machine
This command will copy the public key into the target machine’s authorized keys file.
cat .\.ssh\reliablechair.pub | ssh reliablechair "mkdir -p .ssh && cat >> .ssh/authorized_keys"
Update entry in SSH config
Switch the entry for reliablechair
to use the SSH key. Setting AddKeysToAgent
to yes
will add the key to your ssh-agent
session. This means that if you set a passphrase on the key, you won’t have to enter it after the initial session.
Host reliablechair
User user
HostName reliablechair.lan
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile c:\Users\Ryan\.ssh\reliablechair
AddKeysToAgent yes
ssh-add
You can also call ssh-add
directly.
ssh-add $env:HOME\.ssh\reliablechair
SSH connection profile for Windows Terminal
Open the Windows Terminal settings. Add a new entry under profile > list
. Use a new GUID for each entry.
{
"guid": "{474e775e-4f2a-5b96-ac1e-a2962a402335}",
"hidden": false,
"name": "Reliable Chair",
"commandline": "ssh reliablechair"
}
Now there is an option to open a connection to reliablechair
in the new tab menu for Windows Terminal.
Wrap-up
With a little configuration, it is easy to create SSH sessions from Windows Terminal.
- linux
- ssh
- tutorial
- windows terminal
Do you know that Windows 10 and 11 or above have SSH pre-installed on them? Yes, Windows has a built-in OpenSSH client that you can use with the help of Windows Terminal.
What is OpenSSH?
OpenSSH-based secure shell (SSH) client, for secure key management and access to remote machines.
You can find the SSH Client located at C:\Windows\System32\OpenSSH
How to use SSH on Windows 11 Terminal
- Press Windows key to open search and type Terminal and select «Windows Terminal«.
- Now move to C:\Windows\System32\OpenSSH
cd C:\Windows\System32\OpenSSH
- Now run the SSH command to connect to a server.
Syntax:
ssh username@remote-server
Example:
ssh mike@192.178.91.121
The default port is 22.
You can download this article in various formats for your convenience. Choose from the options below:
Facing issues? Have Questions? Post them here! I am happy to answer!
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
Статья больше актуальна для Windows 10, ведь это самая прекрасная операционная система для десктопа.. Но без Linux наш мир не обойдется, поэтому многим людям приходится подключаться по ssh к своим серверам, будь они на отдельном компе или на запущенной виртуальной машине, различное окружение для разработки, атс на Asterisk и просто роутер или файлопомойка, все это обычно на Линуксе, он легкий, гибкий и может быть запущен на любом одноплатнике.
Ни для кого не секрет, что в Windows 10 есть терминал со вкладками и ssh, для этого даже не требуется устанавливать WSL, в простом PowerShell можно набрать ssh user@host и работать по ssh
Для того, чтобы не вводить каждый раз пароль, нам нужно сгенерировать ключ ssh
ssh-keygen
//дальше просто энтер жмем и все
А дальше прокинуть ключ на сервер
cat ~/.ssh/id_rsa.pub | ssh user@192.168.200.100 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Но остается один момент, лень вводить имя пользователя для подключения по SSH, если имя локального пользователя отличается от удаленного
Для этого заходим в папку C:\Users\Username\.ssh
, в ней открываем или создаем файл config и пишем или дописываем такое
Host 192.168.0.2
HostName 192.168.0.2
User username111
Тепеоб просто можем вводить ssh 192.168.0.2
и заходить на нужный сервер, у меня в локальной сети несколько таких серверов и еще виртуалками развернуто несколько.