SSH Keys with 1and1 Hosting
I recently upgraded my hosting package with 1and1 and now able to use SSH to connect to my webserver! There were a few different places out there that I had to piece together in order to setup my SSH keys with the 1and1 server so I decided I would consolidate my findings here.
Generating Your Key Pair to Use with 1and1
user@machine:~$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_dsa): /home/user/.ssh/1and1_hosting
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/gbrands/.ssh/1and1_hosting.
Your public key has been saved in /home/gbrands/.ssh/1and1_hosting.pub.
The key fingerprint is:
I use a lot of SSH connections in my line of work and I try to keep them as separate as possible by generating a unique SSH key pair for each of the servers I connect to. By specifying the file in which to save the key, you are able to have a unique pair for each of the hosts.
I also like to specify a passphrase for the key just to be on the safe side. A family member could possibly use my computer and accidentally execute one of the commands I issued last and connect to the remote server and specifying a simple passphrase prevents this from occurring.
However, you could just use the default and hit enter for each of the prompts.
Adding Your 1and1 User Name to the Config File
Chances are your 1and1 user name used to connect via SSH (the same as the main FTP user) is different than that of your local user account on your machine. In order to circumvent having to use the 'l' flag everytime with SSH, I found it much easier to provide a config file with this information. You would save this locally in your ~/.ssh directory
~/.ssh/config (if this file doesn't exist, just create one)
Now you will be able to just type in
Adding Your Public Key to 1and1
Once you have generated your key pair, the next step is to add it to your 1and1 web server. By default, you don't have an
.ssh directory in your home directory (at least I didn't). So you'll have to make one and add your public key to an authorized keys file.
(uiserver):1and1user:~ > mkdir .ssh
(uiserver):1and1user:~ > cd .ssh/
(uiserver):1and1user:~/.ssh > vi authorized_keys2
(uiserver):1and1user:~/.ssh > exit
Connecting to your 1and1 Web Server
Now that you have your SSH key pair added to the 1and1 server, you should now be able to connect by simply typing in the command