Alesbi
Posts: 109
Joined: Wed Aug 22, 2012 3:18 pm

Re: SSH not working

Wed Sep 05, 2012 12:26 am

jojopi wrote:I doubt that you can regenerate the keys from a GUI. You also definitely need to be root to do so. (Even if ubuntu let you write to the foreign disk, the ssh daemon on the Pi would reject keys that have the wrong ownership.)

The commands I gave assumed the card would be mounted on /mnt. The designer of the GUI has decided not to tell you where the card is actually mounted, just calling it "1.9 GB Filesystem", which is both stupid and unhelpful ;)

If you open a terminal you should be able to become root with something like "sudo su -". Look at "df -m" to work out where the 1762M partition has auto-mounted; probably somewhere under /mnt or /media. cd to the etc/ssh subdirectory of the card, maybe with something like "cd /media/10b4c001-2137-4418-b29e-57b7d15a6cbc/etc/ssh". These commands assume you are in the right directory:

Code: Select all

mv ssh_host_* ../../root
yes |ssh-keygen -q -N "" -t rsa -f ssh_host_rsa_key
yes |ssh-keygen -q -N "" -t dsa -f ssh_host_dsa_key
yes |ssh-keygen -q -N "" -t ecdsa -f ssh_host_ecdsa_key 2>/dev/null
sync
There should be no errors reported. Close the terminal window and eject the filesystem with the GUI button before unplugging the card.
I'm sorry but you, sir, are an absolute freaking legend! Idk how you knew those commands would work, but they did! SSH now running successfully on Raspbian. Hooray! Thanks as well to everyone else that helped, including drgeoff and Jim Jkla, your input is much appreciated!

As a matter of learning, would you mind telling me what these commands actually did? I realise they reset my SSH keys, or did SOMETHING to my SSH keys, but I'm sure its more detailed than that.


Now I just need to get a working keyboard, try and get a working monitor and try to fix the SSH keys on Raspbmc (Which is proving a tad more difficult at the moment, though - there doesnt seem to be /etc/ssh directory). Also, installing Raspbmc is a little difficult with my router and TV in entirely different parts of the house :D

Alesbi
Posts: 109
Joined: Wed Aug 22, 2012 3:18 pm

Re: SSH not working

Wed Sep 05, 2012 1:00 am

Trying to fix the SSH keys on Raspbmc is more tricky. After performing the same steps as for Raspbian, I get Connection Refused still when I try to SSH. This mite have something to do with Raspbmc not being fully set up, as I don't have a monitor+router in the same room to allow me to do the initial set up.

User avatar
jojopi
Posts: 3041
Joined: Tue Oct 11, 2011 8:38 pm

Re: SSH not working

Wed Sep 05, 2012 7:55 pm

Alesbi wrote:As a matter of learning, would you mind telling me what these commands actually did? I realise they reset my SSH keys, or did SOMETHING to my SSH keys, but I'm sure its more detailed than that.
SSH uses public-key cryptography to authenticate the server to the client. The purpose of this is to ensure that you are connecting to the correct machine — it has the same keys as last time — so that you can not be tricked into giving your password to an imposter.

Early OS images for the RasPi included host keys in the image file. But this was not actually secure because it meant the keys were not secret and any system could impersonate any other. Newer images create the keys on the first boot so that they are different on every Pi.

SSH can use one of three different algorithms for host authentication: RSA, DSA, or ECDSA; the client and server agree which one to use during connection. Each algorithm needs its own type of key, and each key has two files, private and public. So altogether there are up to six files named /etc/ssh/ssh_host_*. (Eight if the machine supports the obsolete SSH protocol version 1 as well.)

"ssh-keygen" is the program that creates new keys (and performs various other helper tasks). By default it creates user keys for authenticating a user to a remote server, but run as root with the right options, it can create host keys instead.

In your case, we suspected a problem with the host keys, so we moved all six files out of the way and created new key pairs manually using ssh-keygen on another machine. We still do not know exactly what was wrong with the original files. It may be that an inadequate power supply or a crash on the first boot interfered with the process of generating or saving one or more of the files.

It would be interesting to see the output of the following commands:

Code: Select all

cat /var/log/regen_ssh_keys.log
sudo ls --full-time /root
sudo zgrep -h sshd.*error /var/log/auth.log*
The first shows the logs from the process that generated the original keys on the first boot. The second will show the time stamps and file lengths of the original files that we (hopefully) managed to preserve by moving to /root. The third should find the errors that the ssh server very likely logged each time it reset your client connections. (This is likely to include the same messages repeated lots of times. We only need one copy.)

Alesbi
Posts: 109
Joined: Wed Aug 22, 2012 3:18 pm

Re: SSH not working

Mon Sep 10, 2012 12:26 am

jojopi wrote:
Alesbi wrote:As a matter of learning, would you mind telling me what these commands actually did? I realise they reset my SSH keys, or did SOMETHING to my SSH keys, but I'm sure its more detailed than that.
SSH uses public-key cryptography to authenticate the server to the client. The purpose of this is to ensure that you are connecting to the correct machine — it has the same keys as last time — so that you can not be tricked into giving your password to an imposter.

Early OS images for the RasPi included host keys in the image file. But this was not actually secure because it meant the keys were not secret and any system could impersonate any other. Newer images create the keys on the first boot so that they are different on every Pi.

SSH can use one of three different algorithms for host authentication: RSA, DSA, or ECDSA; the client and server agree which one to use during connection. Each algorithm needs its own type of key, and each key has two files, private and public. So altogether there are up to six files named /etc/ssh/ssh_host_*. (Eight if the machine supports the obsolete SSH protocol version 1 as well.)

"ssh-keygen" is the program that creates new keys (and performs various other helper tasks). By default it creates user keys for authenticating a user to a remote server, but run as root with the right options, it can create host keys instead.

In your case, we suspected a problem with the host keys, so we moved all six files out of the way and created new key pairs manually using ssh-keygen on another machine. We still do not know exactly what was wrong with the original files. It may be that an inadequate power supply or a crash on the first boot interfered with the process of generating or saving one or more of the files.

It would be interesting to see the output of the following commands:

Code: Select all

cat /var/log/regen_ssh_keys.log
sudo ls --full-time /root
sudo zgrep -h sshd.*error /var/log/auth.log*
The first shows the logs from the process that generated the original keys on the first boot. The second will show the time stamps and file lengths of the original files that we (hopefully) managed to preserve by moving to /root. The third should find the errors that the ssh server very likely logged each time it reset your client connections. (This is likely to include the same messages repeated lots of times. We only need one copy.)
Thanks for the lesson. I went to run those commands, but when I plugged my Pi in, the network lights came on, the light on the router came on, but I couldnt find the Pi under "Attached Devices" - seems it wasn't assigned an IP. It may be because I messed around with the "interfaces" file whilst trying to do something. Might just re-install Raspbian and hope that fixes it. If/When I do fix it, I'll post the output to those commands.

phalkie
Posts: 1
Joined: Thu Jun 12, 2014 9:12 pm

Re: SSH not working

Thu Jun 12, 2014 9:14 pm

Solved: in Raspbmc settings, in System Configuration tab, enable SSH server and restart Pi.

Cockroach
Posts: 3
Joined: Wed Mar 16, 2016 3:00 pm

Re: SSH not working

Wed Mar 16, 2016 3:12 pm

Hi, i have one question.


Is possible that if is Raspberry too far away from router (cca 20m and signal lvl is about <20% ), then i'm kicked out from putty.?Sometimes i cant log in, but sometimes i can log in but after five min i'm out. And putty says "Network error: Software caused connection abort ".& "error:Connection timed out"

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: SSH not working

Wed Mar 16, 2016 4:21 pm

I assume your talking wi-fi here you can boost your signal by making a tinfoil reflector to make your signal stronger & dirctional. ;)
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

Return to “Troubleshooting”

Who is online

Users browsing this forum: gkreidl and 38 guests