13

My RPi is running Raspbian. I am trying to get SSH set up.

I followed these steps to get a static IP on my Pi:

  1. Since my PC was connected to the LAN via WiFi, I used ipconfig to get the IP address, gateway, etc. of my WLAN card
  2. I used this data to set up a static IP in Raspbian, changing the IP address of course.

ifconfig confirms that I have set up the static IP correctly.

I have tried to connect to the Pi using PuTTY on my Windows 7 PC. PuTTY throws the following error message:

connection timed out when connecting

Additionally, when I tried to ping the Pi's static IP address, I didn't get any reply from RPi, instead getting "connection timed out".

Was copying the information from my working PC the wrong thing to do? How can I fix this and get working SSH on my Pi?

nc4pk
  • 1,378
  • 1
  • 13
  • 25
nbsrujan
  • 567
  • 3
  • 6
  • 16

5 Answers5

11

A couple of things to try:

  1. Are you able to ping the Raspberry Pi from the windows machine, open a command prompt and enter ping 192.168.0.198 (but with the IP address you are using for SSH), if you get replies the connection is good, if not there is a networking problem preventing SSH working
  2. Did you set-up SSH using raspi-config, or did you set it up yourself, if you set it up yourself can you tell us how (there may be a set-up issue with SSH)
  3. Can you log in to SSH from the Raspberry Pi itself, use ssh 127.0.0.1 (actually use 127.0.0.1), if this does not work then it is likely that SSH is not set-up correctly, the error may give a clue to the problem.
  4. Can you now try to log in to SSH from the Raspberry Pi itself, but this time use the actual address and port ssh 192.168.0.198 -p 22 (but with the IP address you are using for SSH), if this does not work it may point to a problem with the firewall on Linux, or that SSH is set-up to only use certain connections or a different port number
  5. If all of the above work fine then it is probably something like a firewall problem with the router, it may help to try some different port numbers

To add extra port numbers do the following:

  • Backup the SSH configuration using sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.old
  • Edit the SSH configuration using sudo nano /etc/ssh/sshd_config
  • Look for the line that says Port 22
  • Add some additional lines below with some other port numbers, I would suggest a different well-known number, e.g. Port 80, and a largish number, e.g. Port 55555
  • Restart the SSH service using sudo /etc/init.d/ssh restart
  • Try using putty with each number you added in turn, in my case 80 does not work because we have a web server the router forwards to, but 55555 worked fine

Hopefully something here helps, let us know what happens

PiBorg
  • 1,497
  • 10
  • 11
  • Sir, thanks a lot. Adding extra ports really really helped me a lot. I was stuck with SSH from 2 weeks. Another problem with my RPi could be DNS server address in RPi and PC are not same. This also could be a reason :) – nbsrujan Jul 10 '13 at 16:34
  • Changing the ssh port solved the problem. Thanks for the answer. – BenRoe Jan 24 '15 at 16:42
  • I can connect to myself, but no matter what I do I cannot connect with Putty, while I can ping my pi IP adress without any problem. What could be the problem? Could it be that my router is blocking somehow this connection? – saldenisov Jul 08 '17 at 13:32
  • I have the same exact problem. This is the code I get: – most venerable sir Jun 05 '18 at 13:44
1

It is possible that Raspi can kick me out of putty and session if is it is too far away from router and the signal level is under 20%.

My opinion is this: Raspberry needs a good signal level, because if the signal level is low the Raspberry disconects from the wifi network (sometimes I can see it connected, sometimes not, but when I log in and want to start script ... it's over and raspberry disconect from network).

goldilocks
  • 58,859
  • 17
  • 112
  • 227
Cockroach
  • 11
  • 1
1

Since your Raspberry Pi is directly connected to your PC you should choose static IPs in a network different from your WIFI network otherwise Windows will probably try to use the WIFI interface to access the RPi.

For example if your WIFI network is 192.168.0.xxx use 10.2.2.xx for the RPi and the wired interface on your PC.

Configure the Rpi with 10.2.2.2 (netmask 255.255.255.0 or /24) and the PC with 10.2.2.3 (also 255.255.255.0 netmask) on the wired interface. You should be able to ssh from your PC to 10.2.2.2.

Be aware that the Raspberry Pi will not be able to access the internet unless you configure windows as a gateway which is out of scope for this answer.

Craig
  • 3,014
  • 13
  • 15
0

After verifying the RaspberryPi's ip address (ifconfig), and setting my PC's ip address to a static one, I kept getting a timeout when I pinged "ping raspberrypi.local". The most important thing I forgot was to be sure that whatever my RaspberryPi's ip address is (198.168.1.3) that my PC's static ip is similar (ex., 198.168.1.2)!!!! This will enable you to connect.

0

In my case the answer was a high traffic of transmission torrent client on the desktop.

If anybody else has the same problem first check your network speed.

Darth Vader
  • 4,206
  • 24
  • 45
  • 69
Nikita
  • 11
  • 1