Can’t import keys for cPanel users?

So you have a webhost that accepts SFTP connections but not nessisarily SSH (it does happen). You've got used to using cPanel to add new keys for your various systems, but the latest builds of cPanel complain that the "filename is invalid" whenever you attempt to import a new key. Here's one potential workaround I figured out this evening if you already have another machine authorised.

The typical scenario

There are several different ways to do this on Mac OS X, Linux and other *nixes, but typically when I'm setting up a webhost for a friend/client I go through roughly this process.

Fire up a Terminal and create a new public/private keypair. Accept the default location for the key file, and enter a password when requested.

% ssh-keygen -b 1024 -t dsa

Navigate to your home folder's ~/.ssh folder and display your new public key.

% cd ~/.ssh
% cat id_dsa.pub

Copy the resulting key in all its pseudorandom glory to the clipboard.

Click Import Key. Choose a name for your key, paste your new public key into the second of the two large text boxes, and click Import.

Under the Public Keys heading, click the Manage Authoriszation link that corresponds to your new key, then click the Authorize button.

Done! You can now more securely access your webhost's SFTP server from that machine.

The problem

Okay so here's where we had some trouble this afternoon. After we'd gone through this process, cPanel choked after step 5 and refused to accept the new key, citing Invalid Filename as an error. Even if we left the key name as the default is_dsa, it would still return the same error.

Fortunately, there's a way to bypass step 5 by uploading our new key manually.

Create the new key as before.

% ssh-keygen -b 1024 -t dsa

Navigate to your home folder's ~/.ssh folder and duplicate the new public key file with the name you would have elected to give it in step 5.

% cd ~/.ssh
% cp id_dsa.pub your_custom_name.pub

Fire up an SFTP session and upload your new public key file into your remote ~/.ssh folder.