Create a private key / public key in CentOS8.2 and connect to SSH with VS Code

Introduction

I used to make an SSH connection to an AWS server, but when I ran CentOS in a local development environment, I made a note of it because I needed to create a key and so on.

environment

Server side CentOS8.2 Client side Windows 10 (SSH client software VSCode)

Premise

-Remote-SSH is installed in VS Code Reference: Develop on EC2 using VSCode's Remote --SSH function -Tar is installed on the server

Big flow

① Create a private key / public key on the server side ② Upload the private key to the client side ③ SSH connection to the server with VS Code

① Create a private key / public key on the server side

It seems that the creation of the private key / public key is mechanically done on the server side or the client side, but it seems that it is more common to transfer the public key created on the client side to the server side. This time, I wanted to create a key on Linux, so I will create it on the server side (CentOS).

Create private / public key


# ssh-keygen -t RSA -b 4096
Generating public/private RSA key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): 
Enter same passphrase again:

ssh-keygen is a command to create a private key and a public key. Format ssh-keygen -t encryption method -b number of bits Option -t Specify encryption method -b Specify the number of bits

If you did not specify a location with the -f option, you will be asked if you want to save it in /root/.ssh/id_rsa and press ENTER. You will be prompted to enter the passphrase to set as the private key, just press Enter without it.

Creation completed


# ssh-keygen -t RSA -b 4096
Your identification has been saved in /root/.ssh/id_rsa.  
Your public key has been saved in /root/.ssh/id_rsa.pub.  
The key fingerprint is:  
SHA256:7YG9R04q702Nje8GSOEH7kdrgrsgrsgLYbTqNTbWvU [email protected]  
The key's randomart image is:  
+---[RSA 4096]----+  
|                 |  
|  .+ .. . o      |  
| .+.=..+ o o     |  
|.. o++. o++ .    |  
|.  ooo. SE+oo    |  
| o .+o   .oB.=   |  
|  +o.   . + *.o  |  
|   .o    o + ..  |  
|  .. .   .o .oo  |  
+----[SHA256]-----+

~/.ssh/Make sure the key is created in


# ls -al ~/.ssh/
-rw-------.1 root root 3389 November 3 01:08 id_rsa 
-rw-r--r--.1 root root 752 November 3 01:08 id_rsa.pub

Modify the public key filename to authorized_keys.

Authorized public key filename_Fixed to keys


# mv id_rsa.pub authorized_keys

This completes the public and private key generation. Then move the private key to the client side.

② Upload the private key to the client side

You can use the scp command, but this time I moved it to the client side using the function of Teraterm. File→SSH_SCP From /root/.ssh/id_rsa To any Windows folder Reference: How to easily transfer files with Teraterm without using commands

④ SSH connection to the server with VS Code

Click on the monitor-like icon in the left pane of VS Code Since the remote explorer opens, press + on the right side of SSH TARGETS The command input screen opens, so enter the following ssh -l root -i" Private key path in Windows folder "Ssh server host name or IP address Press Enter to complete the connection.

SSH is a command to connect to another host using the ssh protocol. Format ssh option host name Option -l Specify user -i Specify the private key

Recommended Posts

Create a private key / public key in CentOS8.2 and connect to SSH with VS Code
How to encrypt and decrypt with RSA public key in Java
Let's create a Docker container that can connect to CentOS 8 with the minimum configuration by SSH
How to SSH into Ubuntu from a terminal with public key authentication
Connect with VS Code from a Windows client to Docker on another server
How to display a browser preview in VS Code
Link Docker log to AWS CloudWatch and monitor in real time with VS Code
Create a Java (Gradle) project with VS Code and develop it on a Docker container
Create a Java (Maven) project with VS Code and develop it on a Docker container
Create a VS Code Plugin.
A memo to start Java programming with VS Code (2020-04 version)
Create a private repository in Amazon ECR and push/pull the image
How to rename a model with foreign key constraints in Rails
How to open a script file from Ubuntu with VS code
Install Ubuntu Server 20.04 in VirtualBox on Mac and connect with SSH
Create a page control that can be used with RecyclerView
When is it said that you can use try with a Swift error?
A ruby ​​script that creates an rsa private key that can be used with OpenSSL from any two prime numbers
Create a private key / public key in CentOS8.2 and connect to SSH with VS Code
(For myself) Build an IDE that you can touch from a browser with docker (trial)
Until you create a local network with CentOS8 and make an ssh or DB connection between locals.
How to test a private method in Java and partially mock that method
Create a program to post to Slack with GO and make it a container
How to create a server executable JAR and WAR with Spring gradle
Have a tool to create and open a new canvas in Mac preview
Connect to Amazon EC2 with SSH (Ubuntu)
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
A memo to simply create a form using only HTML and CSS in Rails 6
[Spring sample code included] How to create a form and how to get multiple records
From creating a Spring Boot project to running an application with VS Code
[Memo] Create a CentOS 8 environment easily with Docker
Create a CSR with extended information in Java
[Rails] rails new to create a database with PostgreSQL
Run a Spring Boot project in VS Code
Code to escape a JSON string in Java
Try searching for a zip code with REST API using SpringBoot, H2 DB and JPA REST-Only 3 classes to create-
How to create a theme in Liferay 7 / DXP
How to easily create a pull-down in Rails
Make a snippet for Thymeleaf in VS Code
Create Spring Boot environment with Windows + VS Code
Try debugging a Java program with VS Code
How to deploy VS Code Remote Containers in a docker-compose project that includes both the API and the front app
Build a Java development environment with VS Code
What I was addicted to when developing a Spring Boot application with VS Code
Until you build a Nuxt.js development environment with Docker and touch it with VS Code
Until you create a Spring Boot project in Intellij and push it to Github
[Azure] I tried to create a Java application for free ~ Connect with FTP ~ [Beginner]
Docker command to create Rails project with a single blow in environment without Ruby
Create a Java Servlet and JSP WAR file to deploy to Apache Tomcat 9 in Gradle
How to implement UICollectionView in Swift with code only
How to create a Java environment in just 3 seconds
I started MySQL 5.7 with docker-compose and tried to connect
I tried to create a Clova skill in Java
How to create a data URI (base64) in Java
[Java] Refer to and set private variables with reflection
Create a user with an empty password on CentOS7
[How to insert a video in haml with Rails]
Connect with port forwarding with SSH and send and receive files
How to convert A to a and a to A using AND and OR in Java
How to build Java development environment with VS Code
[Environment construction] Build a Java development environment with VS Code!
Beginners create Spring Tools Suite environment with VS Code
Ssh connect from container to git with VSCode Remote Container
Connect to Access database with Java [UCan Access] * Set until it can be executed with VS Code
How to develop in a container with --privileged and / sbin / init passed in VSCode Remote Containers