Trouble trying to set up SSH key

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read this

Trouble trying to set up SSH key

Postby gazzc77 on Wed Mar 13, 2013 4:43 pm

Hi there, I am new to linux, having only started using it last week. I have some basic understanding of how it works from reading online tutorials and have managed to get quite a few things set up and working just how I want them but I am having trouble getting SSH to work without password authentication and instead using a key. I must have spent a good 4 hours now and each time I get the same reply that the 'server refused out key' and was hoping somebody here can help me. :)
There are a variety of tutorials to do this that I have seen but they all list slightly different or contradicting methods or have poor English and are hard to understand for a beginner and none so far have resulted in a successful authentication via the key.

So I will give some details and hope for a reply:

I am logging into the box via windows using putty and this program is pretty self explanatory for most of it, I have created a public and private key using the putty generator and made sure putty uses that key when connecting (for troubleshooting purposes I left the key password blank).
After this is where I get confused, the websites I visit all show different formatting for how I should paste this key into the authorized_keys file so my problem may lie here, some sites say to add bits to the end of the key, others say to delete bits, some say to make sure there is a blank space at the start and some don't. I also have conflicting advice on what permissions to set.
Finally I am also unsure of exactly where the authorized_keys file should go.

In the sshd_config file I have changed the default ssh port for security reasons and set rsaa and pubkey authentication to yes, the authorized keys file was default set to %h/.ssh/authorized_keys so I left it as this but the .ssh folder did not seem to exist on my system so I created it and placed the file in there however due to my inexperience I am not sure if I created it in the correct location, I assumed %h sets it to the /home directory so created the .ssh folder in /home by changing to the directory and doing mkdir .ssh and created the authorized_keys file there. Just to be sure I also created the exact same file and folder in /home/myusername/

This is about as far as I get and each time authentication always fails and it is about to make me give up if I can;t find a solution soon :D
gazzc77
Level 1
Level 1
 
Posts: 1
Joined: Wed Mar 13, 2013 4:21 pm

Linux Mint is funded by ads and donations.
 

Re: Trouble trying to set up SSH key

Postby cryptotheslow on Thu Mar 14, 2013 7:19 pm

%h refers to the user's home directory - /home/myusername as you stated.

When generating your key pair in PuTTYgen use the SSH2-RSA option with 1024 bits.

There should be no need to add or remove bits from the public key when adding it to the authorized_keys (or authorized_keys2) file. Just copy your public key file to your ~/.ssh folder then simply append it into the authorized_keys file with:
Code: Select all
cat your_pub_key.file >> authorized_keys


As you're just setting this up and you're not sure what's where it'd probably be best to delete your authorized_keys file before doing the above so you are starting from a known point.

Depending what version of sshd is running it may expect SSH2 keys to appear in ~/.ssh/authorized_keys2 (my Ubuntu server seems to like them in there!). To cover both scenarios put your public key in there too
Code: Select all
cat your_pub_key.file >> authorized_keys2


Delete your public key file from the .ssh folder.

Set the permissions on the two keys files:
Code: Select all
chmod 644 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/authorized_keys2


Set the permissions on the .ssh folder:
Code: Select all
chmod 700 ~/.ssh


That should be it.
cryptotheslow
Level 1
Level 1
 
Posts: 4
Joined: Thu Mar 14, 2013 6:30 pm


Return to Newbie Questions

Who is online

Users browsing this forum: Bing [Bot] and 27 guests