> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Accessing your account using SSH keys

> You can use SSH keys to set up automated SSH logins, or two-factor authentication for increased security. Learn how in this article.

This article describes how to create and deploy SSH keys. With SSH keys, you can automate logins to your hosting.com account, or use two-factor authentication for increased security.

<Note>
  This article describes how to configure SSH keys using the command line. Alternatively, if your hosting account includes cPanel, you can use its graphical user interface to configure SSH keys. For more information, please see [this article](/docs/configuring-ssh-keys-with-cpanel).
</Note>

## Using SSH keys

When you log in to your account interactively using an SSH client as described in [this article](/docs/using-ssh-secure-shell), you must enter a password every time. But what if you want to run an automated process? Perhaps you want to automatically download a database backup at certain times to your local computer. In this scenario, you don't want to have to manually type your SSH password every time the backup process runs.

Or what if you want to allow multiple users to transfer files securely using SFTP, as described in [this article](/docs/setting-up-sftp-access-for-multiple-users)? You would need to give them your cPanel password, which would give them complete access to your account.

You can solve these problems by using SSH keys to connect to your account. SSH keys enable your computer to log in to your hosting.com account automatically without you typing a password. To use SSH keys, you must first create a public key and private key (also known as a key pair). The client's private key stays on your local computer, while the public key resides on the hosting.com server.

Alternatively, you can also create SSH keys and protect them with a passphrase for two-factor authentication. Although this configuration does not enable automatic logins, it does provide an extra layer of security, because you must have the correct key file*and* know the correct passphrase to access the account.

To set up SSH keys, follow the appropriate procedure below for your computer's operating system.

### Windows operating systems

#### Windows 10 and 11

Windows 10 and 11 include native SSH programs. To generate and configure a key pair, follow these steps:

1. To open the **Run** dialog box, press Windows key+r.

2. In the **Run** dialog box, type `cmd` and then click **OK** to open a command prompt window.

3. At the command prompt, type the following command:
   ```bash theme={null}
   ssh-keygen
   ```

4. Press Enter when you are asked where to save the key.

5. You can optionally add a passphrase to the key. If you are generating keys to use in automated processes, you should just press Enter. However, if you want to set up two-factor authentication by using key files and a password, then type a password for the key and then press Enter.

6. At the command line, type the following command:
   ```bash theme={null}
   more .ssh/id_rsa.pub
   ```

7. Select the text listed in the file and copy it.

8. Log in to your hosting.com account using SSH. At the command line, type the following command, replacing ***username*** wih your hosting.com username, and ***example.com*** with your site's domain name:

   ```bash theme={null}
   ssh username@example.com
   ```

   > 🚧 Important
   >
   > To use a different port number, use the **-p** option. For example:
   >
   > ```bash theme={null}
   > ssh -p 7822 username@example.com
   > ```

9. At the command line on the server, type the following commands:
   ```bash theme={null}
   mkdir ~/.ssh
   nano ~/.ssh/authorized_keys
   ```

10. In the nano text editor, paste the public key text that you copied in step 7.
    > 🚧 Important
    >
    > If you are setting up multiple key pairs, the *authorized\_keys* file may already contain data for other key pairs. If this is the case, then just append the new public key text to the file; do not delete the existing key information.

11. Press Ctrl+x, type `y` to save the file, and then press Enter. nano saves the file and exits.

12. At the command line on the server, type the following commands to set the correct file permissions:
    ```bash theme={null}
    chmod 600 ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
    ```

13. To close the connection, type `exit` and then press Enter.

At this point, you have created the SSH key pair and deployed the client's public key to the hosting.com server. You are now ready to connect to your SSH account using the private key. To do this, follow these steps:

1. At the command prompt, type the following command. Replace ***username*** with your hosting.com username, and replace ***example.com*** with your site's domain name:

   ```bash theme={null}
   ssh username@example.com
   ```

   > 🚧 Important
   >
   > To use a different port number, use the **-p** option. For example:
   >
   > ```bash theme={null}
   > ssh -p 7822 username@example.com
   > ```

2. The SSH client should connect without asking you to type your account password. If you set a passphrase for the key, however, you must type the key passphrase. When you are connected, the remote server's command line prompt appears:
   ```bash theme={null}
   username@hostname [~]#
   ```

3. You can now run commands on the remote server. For example, to see a listing of the current directory, type `ls` and then press Enter.

4. To close the SSH connection when you are done, type `exit` and then press Enter.

5. To close the command prompt window, type `exit` and then press Enter.

#### Older Windows versions

Older versions of Microsoft Windows do not include the SSH suite of programs, so you must download an SSH key generator program first. Hosting.com recommends PuTTYgen, a free program that you can [download here](http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe). After you have downloaded the PuTTYgen executable to your local computer, you can use it to generate a key pair.

To generate and configure a key pair, follow these steps:

1. Start PuTTYgen.

2. Under **Parameters**, click the **SSH-2 RSA** radio button.

3. Confirm that the **Number of bits in a generated key** value is set to **2048**.

4. Click **Generate**.

5. Move the mouse around to generate random data. After a few seconds, PuTTYgen creates the key.

6. You can optionally add a passphrase to the key. If you are generating keys to use for automated processes, you should skip this step. However, if you want to set up two-factor authentication by using key files and a passphrase, then type a password for the key in the **Key Passphrase** and **Confirm Passphrase** text boxes.

7. Click **Save public key**, choose the folder, type `id_rsa.pub` in the **File name** text box, and then click **Save**.

8. Click **Save private key**, choose the folder, type `id_rsa.ppk` in the **File name** text box, and then click **Save**.
   > 📘 Note
   >
   > If you did not specify a key passphrase, PuTTYgen displays a warning. Click **Yes** to dismiss the warning.

9. Select all of the text in the **Public key for pasting into OpenSSH authorized\_keys file** text box, right-click on the text, and then click **Copy**.

10. Log in to your hosting.com SSH account using PuTTY.

11. At the command line on the server, type the following commands:
    ```bash theme={null}
    mkdir ~/.ssh
    nano ~/.ssh/authorized_keys
    ```

12. In the nano text editor, paste the public key text that you copied in step 9.
    > 🚧 Important
    >
    > If you are setting up multiple key pairs, the *authorized\_keys* file may already contain data for other key pairs. If this is the case, then just append the new public key text to the file; do not delete the existing key information.

13. Press Ctrl+x, type `y` to save the file, and then press Enter. nano saves the file and exits.

14. At the command line on the server, type the following commands to set the correct file permissions:
    ```bash theme={null}
    chmod 600 ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
    ```

15. To close the connection, type `exit` and then press Enter.

At this point, you have created the SSH key pair and deployed the client's public key to the hosting.com server. You are now ready to configure the PuTTY client to connect to your SSH account using the private key.

<Note>
  The following procedure assumes that you have already downloaded and installed the PuTTY client. If you have not already done this, follow the PuTTY setup procedures in [this article](/docs/using-ssh-secure-shell) before proceeding.
</Note>

To configure PuTTY to use your private key, follow these steps:

1. Start PuTTY.

2. In the **Category** pane, expand **SSH**, and then click **Auth**.

3. Under **Authentication Parameters**, click **Browse**.

4. Locate the *id\_rsa.ppk* file that you created in the previous procedure.

5. In the **Category** pane, click **Session**.

6. In the **Host Name (or IP address)** text box, type `username@example.com`. Replace ***username*** with your hosting.com username, and replace ***example.com*** with your site's domain name.

7. In the **Port** text box, type `22`.
   > 📘 Note
   >
   > Make sure you use the correct SSH port number for your account. For example, some hosting accounts use a different port for SSH, such as 7822.

8. Confirm that the **Connection type** radio button is set to **SSH**.

9. In the **Saved Sessions** text box, type a name for the connection. For example, type `My hosting.com account`.

10. Click **Save**.

11. To connect to your SSH account, double-click the connection name in the list. PuTTY should connect without asking you to type your account password. If you set a passphrase for the key, however, you must type the key passphrase.

### macOS and Linux operating systems

Both macOS and Linux include SSH support, so you do not have to download any special programs to generate SSH keys.

To create and configure SSH keys, follow these steps:

1. Open a terminal window. The procedure to do this depends on the operating system and desktop environment.

   * On macOS, click **Applications**, click **Utilities**, and then click **Terminal**.

2. At the command prompt, type the following command:
   ```bash theme={null}
   ssh-keygen -t rsa
   ```

3. Press Enter when you are asked where to save the key.

4. You can optionally add a passphrase to the key. If you are generating keys to use in automated processes, you should just press Enter. However, if you want to set up two-factor authentication by using key files and a password, then type a password for the key and then press Enter.

5. At the command line, type the following command:
   ```bash theme={null}
   cat ~/.ssh/id_rsa.pub
   ```

6. Select the text in the file and copy it.

7. Log in to your hosting.com account using SSH. At the command line, type the following command, replacing ***username*** wih your hosting.com username, and ***example.com*** with your site's domain name:

   ```bash theme={null}
   ssh username@example.com
   ```

   > 🚧 Important
   >
   > To use a different port number, use the **-p** option. For example:
   >
   > ```bash theme={null}
   > ssh -p 7822 username@example.com
   > ```

8. At the command line, type the following commands:
   ```bash theme={null}
   mkdir ~/.ssh
   nano ~/.ssh/authorized_keys
   ```

9. In the nano text editor, paste the public key text that you copied in step 6.
   > 🚧 Important
   >
   > If you are setting up multiple key pairs, the *authorized\_keys* file may already contain data for other key pairs. If this is the case, then just append the new public key text to the file; do not delete the existing key information.

10. Press Ctrl+x, type `y` to save the file, and then press Enter. nano saves the file and exits.

11. At the command line, type the following commands to set the correct file permissions:
    ```bash theme={null}
    chmod 600 ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
    ```

12. To close the connection, type `exit` and then press Enter.

At this point, you have created the SSH key pair and deployed the client's public key to the hosting.com server. You are now ready to connect to your SSH account using the keys.

To connect to your SSH account using the keys, follow these steps:

1. Open a terminal window. The procedure to do this depends on the operating system and desktop environment.

   * On macOS, click **Applications**, click **Utilities**, and then click **Terminal**.

2. At the command prompt, type the following command. Replace ***username*** with your hosting.com username, and replace ***example.com*** with your site's domain name:

   ```bash theme={null}
   ssh username@example.com
   ```

   > 🚧 Important
   >
   > To use a different port number, use the **-p** option. For example:
   >
   > ```bash theme={null}
   > ssh -p 7822 username@example.com
   > ```

   > 👍 Tip
   >
   > In this command, we explicitly specify the username and hostname. However, you can also define the settings for a remote host in your *\~/.ssh/config* file as follows:
   >
   > ```
   > Host example
   >     Hostname example.com
   >     Port 22
   >     User username
   > ```
   >
   > The **Host** value can be any name you want; it is simply a label for the other settings. The **Hostname** value is the remote host you want to access, the port number is 22, and the **User** value specifies your hosting.com account username. With this configuration defined, you can connect to the account by simply using the **Host** value. You do not have to type the port number, username, and hostname each time. The following command demonstrates how to do this:
   >
   > ```bash theme={null}
   > ssh example
   > ```

3. The SSH client should connect without asking you to type your account password. If you set a passphrase for the key, however, you must type the key passphrase.
   > 👍 Tip
   >
   > If you are using a passphrase, you may not want to have to re-type it every time you connect to the remote server. If your computer has OpenSSH version 7.2 or later, you can automatically store the passphrase in the SSH authentication agent. (To determine the OpenSSH version installed on your computer, type **ssh -V** at the command prompt.) Then when you connect to the remote server, you must type the passphrase the first time, but not for any subsequent connections.\
   > To do this, add the following lines to your *\~/.ssh/config* file:
   >
   > ```
   > Host *
   >     AddKeysToAgent yes
   > ```
   >
   > If you are using macOS, add the following line as well:
   >
   > ```
   > UseKeychain yes
   > ```
   >
   > Alternatively, if you have an older version of OpenSSH installed on your computer, you can type the **ssh-add** command to manually store the passphrase in the SSH authentication agent for the duration of your login session.

<Warning>
  **Important**

  If your computer has OpenSSH version 8.8 or later, you may be unable to connect to the server. (To determine the OpenSSH version installed on your computer, type **ssh -V** at the command prompt.) This is because by default, OpenSSH 8.8 and later versions disable RSA signatures using the SHA-1 hash algorithm.\
  To enable RSA signatures with SHA-1 hashes so you can connect to the server, add the following lines to your *\~/.ssh/config* file:

  ```
  HostKeyAlgorithms +ssh-rsa,ssh-dss
  PubkeyAcceptedAlgorithms +ssh-rsa,ssh-dss
  ```
</Warning>

## Related articles

* [Using SSH (Secure Shell)](/docs/using-ssh-secure-shell)

* [Configuring SSH keys with cPanel](/docs/configuring-ssh-keys-with-cpanel)

* [Using SSHFS (Secure Shell Filesystem)](/docs/using-sshfs-secure-shell-filesystem)
