Cannot establish ssh connection to computer on local network
Solution 1
Make sure you install the openssh server in the main PC (where you are trying to ssh into)
sudo apt-get install openssh-server
then check if the Ubuntu firewall is turne on?
sudo ufw status
if yes or no still issue the following command
sudo ufw allow ssh
andsudo ufw reload
Now try to ssh using
ssh user@ip-address-of-the-machine
If this doesn't work try to add the INPUT and OUTPUT firewall rule in IPTABLE
sudo iptables -I INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -I OUTPUT -p tcp --dport 22 -j ACCEPT
sudo iptables-save
sudo service iptables restart
You might have to restart the network manager as well. Good Luck!
Solution 2
Ensure you have the ssh server running by running the below on the machine you wish to connect to:
service ssh status
If that returns start/running, process pid then it is running ok. If not run
service ssh start
and check the output that it starts correctly. If it is started correctly and you still can not ssh to the machine then on the remote host install nmap
apt-get install nmap
Nmap (Network Mapper) is a port scanner which is useful for this kind of stuff. Run the below on the computer you are connecting from
nmap *ipaddress/hostname of computer you are trying to connect to*
and check the 22/tcp or ssh is shown as open.
refer to Ubuntu iptables to learn how to open the ports.
Related videos on Youtube
ovangle
Updated on September 18, 2022Comments
-
ovangle almost 2 years
I've just (re)installed ubuntu 11.10 on my main pc, and the connection times out every time I try to ssh connect to my laptop (over the local network) to retrieve the files I backed up there. The connection times out every time I try to connect.
I can establish a connection in the other direction without issue.
Here's the verbose output I get when I try to connect:
ovangle@ruby-EP43-DS3:~$ ssh -v [email protected] OpenSSH_5.8p1 Debian-7ubuntu1, OpenSSL 1.0.0e 6 Sep 2011 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug2: ssh_connect: needpriv 0 debug1: Connecting to 10.1.1.4 [10.1.1.4] port 22. debug1: connect to address 10.1.1.4 port 22: Connection timed out ssh: connect to host 10.1.1.4 port 22: Connection timed out
ssh is installed on both machines, and I've tried deleting '~/.ssh/known_hosts' on both machines, still nada.
I've changed the sshd logging on the laptop to VERBOSE and restarted the daemon (because I wasn't getting any relevant syslog entries otherwise), and this is the log for the most recent connection attempt.
EDIT: posted wrong logs last time. They just showed that there was a connection received, they weren't actually the sshd logs (which were in auth.log as I recently discovered). Unfortunately, that log is filling up with extremely weird error messages and it gives me no information about the connection.
Nov 8 16:02:18 ovangle-A6Rp pkexec: pam_unix(polkit-1:session): session opened for user root by (uid=1000) Nov 8 16:02:18 ovangle-A6Rp pkexec: pam_ck_connector(polkit-1:session): cannot determine display-device Nov 8 16:02:18 ovangle-A6Rp pkexec[6270]: ovangle: Executing command [USER=root] [TTY=unknown] [CWD=/home/ovangle] [COMMAND=/usr/sbin/gnome-power-backlight-helper --set-brightness 2] Nov 8 16:02:19 ovangle-A6Rp pkexec: pam_unix(polkit-1:session): session opened for user root by (uid=1000) Nov 8 16:02:19 ovangle-A6Rp pkexec: pam_ck_connector(polkit-1:session): cannot determine display-device Nov 8 16:02:19 ovangle-A6Rp pkexec[6273]: ovangle: Executing command [USER=root] [TTY=unknown] [CWD=/home/ovangle] [COMMAND=/usr/sbin/gnome-power-backlight-helper --set-brightness 7]
-
Admin over 12 yearsTry to use verbose, eg. "ssh -vvv username@laptop" and post the relevant output.
-
Admin over 12 yearsDo you have
openssh-server
installed on both machines? -
Admin over 12 yearsupdated the post with the relevant output. Also, both machines have openssh-server installed.
-
Admin over 12 yearsWhat does sshd log on the laptop when connecting to there?
-
Admin over 12 yearson the machine you're trying to connect to do a
sudo service ssh restart
and see what the output is. -
Admin over 12 yearsThe same happens to me, it seems that when you logoff, Network Manager closes and then you are not only unable to conect using ssh, but even to do a single ping. I am currently looking for a solution but what you can do is to just block the screen and do not logoff. This may work.
-
Admin about 10 yearsDon't you have iptables rules on your laptop that would prevent SSH ? Do
iptables -L
to list the rules if they are activated. If you have firewall rules activated, you must have at least one allowing traffic (ACCEPT) to TCP port 22.
-