This article describes how to create and deploy SSH keys. With SSH keys, you can automate logins to your A2 Hosting account, or use two-factor authentication for increased security.
When you log in to your account interactively using an SSH client as described in this article, 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? 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 A2 Hosting 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 A2 Hosting 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.
Older versions of Microsoft Windows do not include the SSH suite of programs, so you must download an SSH key generator program first. A2 Hosting recommends PuTTYgen, a free program that you can download here. 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:
mkdir ~/.ssh nano ~/.ssh/authorized_keys
In the nano text editor, paste the public key text that you copied in step 9.
At the command line on the server, type the following commands to set the correct file permissions:
chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh
At this point, you have created the SSH key pair and deployed the client's public key to the A2 Hosting server. You are now ready to configure the PuTTY client to connect to your SSH account using the private key.
To configure PuTTY to use your private key, follow these steps:
As of April 2018, Windows 10 includes native SSH programs. To generate and configure a key pair, follow these steps:
ssh-keygen
At the command line, type the following command:
more .ssh/id_rsa.pub
Log in to your A2 Hosting account using SSH. At the command line, type the following command, replacing username wih your A2 Hosting username, and example.com with your site's domain name:
ssh -p 7822 username@example.com
At the command line on the server, type the following commands:
mkdir ~/.ssh nano ~/.ssh/authorized_keys
In the nano text editor, paste the public key text that you copied in step 7.
At the command line on the server, type the following commands to set the correct file permissions:
chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh
At this point, you have created the SSH key pair and deployed the client's public key to the A2 Hosting server. You are now ready to connect to your SSH account using the private key. To do this, follow these steps:
ssh -p 7822 username@example.com
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:
[email protected] [~]#
Both Mac OS X 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:
At the command prompt, type the following command:
ssh-keygen -t rsa
At the command line, type the following command:
cat ~/.ssh/id_rsa.pub
Log in to your A2 Hosting account using SSH. At the command line, type the following command, replacing username wih your A2 Hosting username, and example.com with your site's domain name:
ssh -p 7822 username@example.com
At the command line, type the following commands:
mkdir ~/.ssh nano ~/.ssh/authorized_keys
In the nano text editor, paste the public key text that you copied in step 6.
At the command line, type the following commands to set the correct file permissions:
chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh
At this point, you have created the SSH key pair and deployed the client's public key to the A2 Hosting 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:
ssh -p 7822 username@example.com
Host example Hostname example.com Port 7822 User usernameThe 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 7822, and the User value specifies your A2 Hosting 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:
ssh example
Host * AddKeysToAgent yesIf you are using Mac OS X, add the following line as well:
UseKeychain yesAlternatively, 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.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.