Windows SSH key for deploy script Note

Generate an SSH key in Windows 10 with OpenSSH Client

Step 1: Verify if OpenSSH Client is Installed

First, check to see if you have the OpenSSH client installed:

1. Open the Settings panel, then click Apps.

2. Under the Apps and Features heading, click Optional Features.

3. Scroll down the list to see if OpenSSH Client is listed.

  • If it’s not, click the plus-sign next to Add a feature.
  • Scroll through the list to find and select OpenSSH Client.
  • Finally, click Install.

Step 2: Open Command Prompt

1. Press the Windows key.

2. Type cmd.

3. Under Best Match, right-click Command Prompt.

4. Click Run as Administrator.

5. If prompted, click Yes in the Do you want to allow this app to make changes to your device? pop-up.

Step 3: Use OpenSSH to Generate an SSH Key Pair

1. In the command prompt, type the following:

ssh-keygen


2. By default, the system will save the keys to C:\Users\your_username/.ssh/id_rsa. You can use the default name, or you can choose more descriptive names. This can help distinguish between keys, if you are using multiple key pairs. To stick to the default option, press Enter.

Note: If a file with the same name already exists, you will be asked whether you want to overwrite the file.

3. You’ll be asked to enter a passphrase. Hit Enter to skip this step.

4. The system will generate the key pair, and display the key fingerprint and a randomart image.

5. Open your file browser.

6. Navigate to C:\Users\your_username/.ssh.

7. You should see two files. The identification is saved in the id_rsa file and the public key is labeled id_rsa.pub. This is your SSH key pair.

Step 4: Use OpenSSH to Generate an SSH Key Pair

To enable passwordless access, you need to upload a copy of the public key to the remote server.

1. Connect to the remote server and use the ssh-copy-id command:

ssh-copy-id -i [pub file] [remote_username]@[server_ip_address]

2. The public key is then automatically copied into the .ssh/authorized_keys file.

Option 2: Upload Public Key Using the cat Command

Another way to copy the public key to the server is by using the cat command.

1. Start by connecting to the server and creating a .ssh directory on it.

ssh -i [pub file] [remote_username]@[server_ip_address] mkdir -p .ssh

2. Then, type in the password for the remote user.

3. Now you can upload the public key from the local machine to the remote server. The command also specifies that the key will be stored under the name authorized_keys in the newly created .ssh directory:

cat .ssh/id_rsa.pub | ssh [remote_username]@[server_ip_address] 'cat >> .ssh/authorized_keys'

Step 5: Log in to Server Without Password

ssh -i [pub file] [remote_username]@[server_ip_address]


RyanX April 21, 2024
Share this post
Archive