Setup and Connect to a VPS using Windows Terminal (with SSH Keys)
Published: 2024-01-19 12:49:47

---
title: Setup and Connect to a VPS using Windows Terminal (with SSH Keys)
published: true
date: 2022-07-28 13:48:08 UTC
tags: 
canonical_url: https://cherylm.hashnode.dev/setup-and-connect-to-a-vps-using-windows-terminal-with-ssh-keys
---

# Prerequisites

- [Windows Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701)
- OpenSSH - [Get started with OpenSSH](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse)
- A Virtual Private Server or a Virtual Machine running Debian

# Connecting to the VPS for the First Time

1. Connect to the VPS using [PuTTY](https://www.putty.org/), [WinSCP](https://winscp.net/eng/index.php) or similar

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658983646112/LGngyt38l.png)

Make sure auto login name is empty

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658983799631/g-87SVpQF.png)

Click open to connect, to the server, login as root

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1659012376713/BoOaV4jGU.png)

# Initial Server Setup

1. Create a new user and Grant access

2. Update package repositories

3. (if sudo is not installed) Install sudo, and add the new user to the sudo group. newUser is then put into the sudo group which members are allowed to use the sudo command in Debian
```
apt install sudo -y
usermod -aG sudo newUser

```
4. Setup firewall (ufw)

5. (Optional) [Top 8 Things to do after Installing Debian 10 (Buster)](https://www.linuxtechi.com/things-to-do-after-installing-debian-10/)

# Connecting to the SSH Server using SSH Keys

It is safer, faster and more convenient connecting to the server using SSH keys, as it's passwordless. A key pair is created by the user and the public key is stored the server while the private key is stored on the client (usually in the form of a file). Client then send the server the private key for authentication. The server will allow access to anyone with the right private key.

1. Generate the key pair on the client (your computer) In windows powershell

2. Copy the public key (the generated file with .pub extension) to the server 

1. If everything is setup correctly, we should be able to SSH into the server using the follow command. Enter the pass phrase set up earlier
```
 ssh newUser@123.45.6.7 -p 22 -i ~/.ssh/<filename>

```
2. (optional) To connect to the server without having to specify the identity file every time, edit **/.ssh/config** , add the following entry for the VPS. Using the same username, VPS IP and filename used above. "Host" can be anything descriptive
```
Host 123.45.6.7 (newUser)
  HostName 123.45.6.7
  User newUser
  IdentityFile ~/.ssh/<filename>

```
Now we can simply use the following command to connect to the server
```
ssh newUser@123.45.6.7

```

# Setting up shortcut on Windows Terminal

Go to settings in windows terminal

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1659013820891/Hl3eYR8F0.png)

Add a new profile, "+ New empty profile"

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1659013960715/aLmJHITLR.png)

Put the tested ssh command, in the "Command line" input

```
   ssh newUser@123.45.6.7 -p 22 -i ~/.ssh/<filename>

```

Here, we can also customize the icon, theme, font, etc for this profile. Remember to save it and now we can open a new terminal without having to enter username, password and hostname from the Windows Terminal dropdown.