Using Private Key To Ssh



  1. How To Ssh Using Private Key
  2. Ssh Linux Using Private Key
  3. Ssh Command With Key File
  4. Use Private Key Ssh Ubuntu
  5. Using Private Key To Ssh Windows 10
  6. Using Private Key To Login Ssh Putty

Use the ssh-keygen command to generate SSH public and private key files. By default, these files are created in the /.ssh directory. You can specify a different location, and an optional password (passphrase) to access the private key file. If an SSH key pair with the same name exists in the given location, those files are overwritten. SSH clients will typically use /.ssh/identity (ssh v1) or one of /.ssh/idrsa or /.ssh/iddsa (v2) as the default private key. You can change this in /.ssh/config (the IdentityFile parameter - the -i option to SSH actually overrides this. See man sshconfig for details).

Go to your GIT project - Settings - SSH keys Then past the content of your public key in SSH keys Step 3.2: Force SSH Client To Use Given Private Key This is an. Using a set of public/private keys to allow you to log into a remote Linux system or run commands using ssh without a password can be very convenient, but setup is just tad tricky.

Log in with an SSH private key on Linux and macOS

Authored by: Brint Ohearn

This article demonstrates how to use a private key to log in to a Linux®server by using a private key with a Terminal session on macOS®. However,you can follow the same process to use a private key when using anyterminal software on Linux.

How To Ssh Using Private Key

Note: For information about using Secure Shell (SSH) private keys on Microsoft®Windows® operating systems, seeLogging in with an SSH Private Key on Windowsand Generate RSA keys with SSH by using PuTTYgen.

Prerequisites

To complete this process, you need the following software applications:

  • SSH client software that is installed on your Linux or macOS operating system by default.
  • Your favorite text editor. This example uses the vim text editor.
  • Your private key. For more information about generating a key on Linux or macOS, seeConnect to a server by using SSH on Linux or Mac OS X.

Log in with a private key

  1. Using a text editor, create a file in which to store your private key. This example usesthe file deployment_key.txt.

  2. To edit the file in vim, type the following command:

  3. After the editor starts, press i to turn on insert mode.

  4. Paste your private key, such as the one in the following image, into the file.Be sure to include the BEGIN and END lines.

  5. To save your changes, press Esc.

  6. Type :wq to write the file and return to the command line.

  7. Run the following command to change the file permissions to 600 to secure the key. You can also set them to 400.This step is required:

  8. Use the key to log in to the SSH client as shown in the following example, which loads the key in file deployment_key.txt, and logs in as user demo to IP 192.237.248.66:

  9. When you are prompted to confirm the connection, type yes and then press Enter.

  10. If your SSH key requires a password, enter it when prompted to complete the connection.

Share this information:

©2020 Rackspace US, Inc.

Using

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

In order to use public and private key based authentication to SFTP to your server, you need to have SSH enabled on your hosting account. Most hosts do not enable SSH by default, so you might want to check with your host and get it enabled if it isn't already. Once SSH is enabled, connecting to your server is simple. Here are three main steps involved:

  1. Generating public and private Key pairs using Cpanel.
  2. Downloading and converting the private key into PPK (PuTTY Private Key) format.
  3. Connecting to your server using an FTP client and using the PPK key for authentication.

So let's look at these steps in details:

Using Private Key To Ssh

Generating Public and Private Key Pairs Using Cpanel

In order to use SFTP, we first need to generate public and private key pairs. This can easily be done using Cpanel as detailed in the steps below:

Step 1:Login to Your Cpanel and click on SSH Shell Access under the security section.

Step 2: Click on the Manage SSH Keys button and then Click on the Generate a New Key link.

Step 3: On this page, enter the following details:

Key Name: id_rsa
Key Password: Any password. (Note: This is the passpharse that you will need to enter while you SFTP.)
Key Type: RSA
Key Size: 2048

Once all details are entered, click on Generate Key (refer image above). This will generate a public and private key pair. You should now be able to see these files in your Manage SSH Keys page.

Ssh with private key cmd

Step 4: On the Manage SSH Keys page, click on Manage Authorization and then click the Authorize button. This will authorize the key for usage as shown in the image below.

Step 5: Click on the View or Download link in the Private Keys section to covert and download your private key.

Converting Private Key to PPK Format

We now need to convert the private key to PPK format. You can do this using the covert key option on Cpanel, or you can download the raw file and covert it to PPK format using PuttyGen. In most cases, the Cpanel convert option works pretty good, so you can stick with it. But in-case, you don't have that option in your Cpanel account, you can use the Puttygen method. Let's look at both these methods:

Option 1: Converting the key to PPK format using Cpanel Covert key option:

To use this option, enter your passphrase in the space provided and click Convert as shown in the image below. You can then download the converted key to your computer and save it in an accessible location.

Note: The passpharse is the key password that you used while generating the keys in Cpanel.

Option 2: Converting the Key to PPK format Using PuttyGen:

This option involves using PuttyGen to convert the key. If you don't have PuttyGen installed, you can download it free from here. Once downloaded and installed, follow these steps:

Ssh Linux Using Private Key

Step 1: As shown in the image above (marked Option 2), click on the 'Download Key' button on the View or Download SSH Keys page. This will download the private key (id_rsa) to your computer. Copy and save this file in an accessible location.

Step 2: Open the PuttyGen application and click Run.

Step 3: Go to Conversions > Import Key, browse to the location of your downloaded private key file (id_rsa) and select the file.

Once you load the file you will be prompted to enter the passpharse. Enter the passpharse and click ok.

Step 4: Make sure that the SSH2 RSA option is selected and the number of bits is set to 2048.

Step 5: Click on Save private key and save the file with your preferred name. (Refer image above).

SFTP to the Server

Ssh Command With Key File

Now that we have our public and private keys setup, we can SFTP to the server. You can do this using any FTP client like Filezilla or WinSCP. I am using WinSCP for this tutorial.

Step 1: Open WinSCP and create a new FTP connected by clicking on New Site and enter the following details:

File Protocol: SFTP
Host Name: ftp.domainname.com
Port Number: 22
Username: Cpanel Username
Password: Cpanel Password

Step 2: Click on the Advanced botton to open the Advanced Site Settings page as shown in point no.6 in the image above.

Step 3: On the Advanced Site Settings page click on Authentication and then browse to the location of your PPk file. Refer image below:

Use Private Key Ssh Ubuntu

Step 4: Once done, click ok and then click Save to save the settings.

Using Private Key To Ssh Windows 10

Step 5: Click Login to login to your server using SFTP. Once the connection is establised and the server has finished verifing the private and public keys, you will be promoted to enter the passpharse. Enter the passpharse and click Ok.

Using Private Key To Login Ssh Putty

You should now be connected to your server using SFTP.