Can't connect to a server via SSH (with my PC only)

30,378

I've finally found a way to fix the issue I had. I found this article about iptables. It helped me a lot to fix the issue.

The only thing I did is run the command

sudo iptables -F

Doing that has allowed me to push again on remote repositories and thus using ssh. But I had to save that.

For this I run this other command to make all the changements due to the previous command persistent

sudo apt-get update
sudo apt-get install iptables-persistent

I found that thanks the article linked previously. I rebooted in the meantime and everything is working correctly.

Share:
30,378

Related videos on Youtube

Azuk
Author by

Azuk

Updated on September 18, 2022

Comments

  • Azuk
    Azuk over 1 year

    For some days I'm experiencing issues with SSH on my machine (I guess after having installed some softs that I don't remember... (sic))

    It's very problematic as I use Git to work on some code projects with other people, pushing my work on a repository via SSH.

    I'm 100 % sure the problem is coming from my computer (Linux Mint 16 cinnamon), because:

    • From the same Internet connexion (same router, same IP), I can connect without any problem to the same server with another computer. Therefore, it's not a firewall problem coming from the router.

    • The admin of the server doesn't see any issues that could create this concern, and everybody else has access as they should.

    This is the error message Git tells me:

    ssh: connect to host ******* port 22: Connection refused
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    

    Result of command netstat -plant | grep :22

    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1248/sshd       
    tcp6       0      0 :::22    
    

    I was told that could be a problem with my iptables, and have tried to sudo iptables -X (and -F), with no luck. I have no idea how to manage this further...

    EDIT:

    As asked in the comments, I tried to run an ordinary SSH session in verbose mode. Here are the messages I have:

    -$ ssh -v [email protected]
    OpenSSH_6.2p2 Ubuntu-6ubuntu0.4, OpenSSL 1.0.1e 11 Feb 2013
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 19: Applying options for *
    debug1: Connecting to [email protected] [82.165.49.211] port 22.
    debug1: connect to address 82.165.49.211 port 22: Connection refused
    ssh: connect to host [email protected] port 22: Connection refused
    

    Result of command ls -al /var/run/

    total 52
    drwxr-xr-x 25 root       root        820 jan 30 20:49 .
    drwxr-xr-x 24 root       root       4096 oct 14 22:35 ..
    -rw-r--r--  1 root       root          5 jan 30 20:49 acpid.pid
    srw-rw-rw-  1 root       root          0 jan 30 20:49 acpid.socket
    drwxr-xr-x  2 root       root         60 jan 30 20:49 apache2
    drwxr-xr-x  2 avahi      avahi        80 jan 30 20:49 avahi-daemon
    drwxr-xr-x  2 root       root         60 jan 30 20:49 console
    drwxr-xr-x  2 root       root         60 jan 30 20:49 ConsoleKit
    -rw-r--r--  1 root       root          5 jan 30 20:49 console-kit-daemon.pid
    -rw-r--r--  1 root       root          5 jan 30 20:49 crond.pid
    ----------  1 root       root          0 jan 30 20:49 crond.reboot
    drwxr-xr-x  3 root       lp          120 jan 30 20:49 cups
    drwxr-xr-x  2 messagebus messagebus   80 jan 30 20:48 dbus
    srw-rw-rw-  1 root       root          0 jan 30 20:49 gdm_socket
    drwxr-xr-x  2 root       root         40 jan 30 20:49 initramfs
    drwxrwxrwt  3 root       root         60 jan 30 20:49 lock
    -rw-r--r--  1 root       root          5 jan 30 20:49 mdm.pid
    -rw-r--r--  1 root       root        135 jan 30 20:48 motd
    drwxr-xr-x  2 root       root         60 jan 30 20:48 mount
    drwxr-xr-x  2 mysql      root         80 jan 30 20:49 mysqld
    drwxr-xr-x  3 root       root        140 jan 30 20:49 network
    drwxr-xr-x  2 root       root        100 jan 30 20:49 NetworkManager
    -rw-r--r--  1 root       root          5 jan 30 20:49 pglcmd.wd.pid
    -rw-r--r--  1 root       root          5 jan 30 20:49 pgld.pid
    drwxr-xr-x  2 root       root         40 jan 30  2015 plymouth
    drwxr-xr-x  4 root       root         80 jan 30 20:49 pm-utils
    drwxr-xr-x  2 root       root         40 jan 30 20:49 pppconfig
    drwxr-xr-x  3 root       root        100 jan 30 20:49 resolvconf
    -rw-r--r--  1 root       root          4 jan 30 20:48 rsyslogd.pid
    drwxr-xr-x  2 root       root        320 jan 30 20:49 samba
    srw-rw-rw-  1 root       root          0 jan 30 20:48 sdp
    drwxr-xr-x  2 root       root         60 jan 30 20:49 sendsigs.omit.d
    drwxrwxrwt  2 root       root        140 jan 30 20:49 shm
    drwxr-xr-x  6 root       root        120 jan 30 20:49 systemd
    drwxr-xr-x  6 root       root        160 jan 30 20:49 udev
    drwx------  2 root       root         40 jan 30 20:49 udisks2
    -rw-r--r--  1 root       root          4 jan 30 20:48 upstart-file-bridge.pid
    -rw-r--r--  1 root       root          4 jan 30 20:48 upstart-socket-bridge.pid
    -rw-r--r--  1 root       root          4 jan 30 20:48 upstart-udev-bridge.pid
    drwxr-xr-x  3 root       root         60 jan 30 20:49 user
    -rw-rw-r--  1 root       utmp       3840 jan 30 20:50 utmp
    

    Content of /etc/ssh/ssh_config (without "#" comments lines)

    Host *
    # (...)
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials no
    
    • devnull
      devnull over 9 years
      Have you tried disabling your firewall first and see if you can ssh? If it succeeds then it definitely is a bad firewall rule: sudo ufw disable
    • Mark Plotnick
      Mark Plotnick over 9 years
      The error message says uid=1000 pid=6098 comm="start ssh ", which indicates it was running as uid 1000. Try sudo service ssh restart.
    • TheMeaningfulEngineer
      TheMeaningfulEngineer over 9 years
      Can you test an ordinary ssh session with verbose on, to that server? ssh -v [email protected] use the server ip
    • Azuk
      Azuk over 9 years
      @DevNull - I disabled my firewall with the command you showed me but I'm still unable to push to the server.I just have a message telling " the firewall is stopped & disabled during the boot system".
    • Azuk
      Azuk over 9 years
      @MarkPlotnick I ran aswell your command to restart the ssh service, I got as answer this -> "stop: Unknown instance: ssh stop/pre-start, process 8957". I'm still unable to connect.
    • Azuk
      Azuk over 9 years
      @Alan Here is the result I got when trying to connect to the server with the -v parameter ssh -v theuser.onlinehome.fr OpenSSH_6.2p2 Ubuntu-6ubuntu0.4, OpenSSL 1.0.1e 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to theuser.onlinehome.fr [82.165.49.211] port 22. debug1: connect to address 82.165.49.211 port 22: Connection refused ssh: connect to host theuser.onlinehome.fr port 22: Connection refused
    • devnull
      devnull over 9 years
      @Azuk Can you run this command and update your questions with the output ls -al /var/run/
    • TheMeaningfulEngineer
      TheMeaningfulEngineer over 9 years
      Try with maximum verbosity (-vvv)
    • Azuk
      Azuk over 9 years
      @DevNull It still doesn't work, with the first command I indeed get a process /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session etc... It had the id of 2321, so I ran the command to kill it as root. I then restarted the SSH services. It returned top: Unknown instance: ssh stop/pre-start, process 4543 But that still doesn't work. However, there is something odd, after killing the PID and restarting the SSH services I ran again the command to see the SSH processes and the process still appear with the same orginal ID which is 2321.
    • Azuk
      Azuk over 9 years
      @Alan I tested with maximum verbosity and the output is exactly the same as one single -v parameter...
    • TheMeaningfulEngineer
      TheMeaningfulEngineer over 9 years
      It is possible that the server only has ssh enabled for git. Try getting the git to run ssh in verbose. (the link I posted)
    • Azuk
      Azuk over 9 years
      I added the config file as I didn't have one in my .ssh folder and put the code as shown in the link. It seems It doesn't work. Here is what I have when I run again the command with -vvv OpenSSH_6.2p2 Ubuntu-6ubuntu0.4, OpenSSL 1.0.1e 11 Feb 2013 debug1: Reading configuration data /home/geo/.ssh/config /home/geo/.ssh/config line 2: unsupported log level '(QUIET|FATAL|ERROR|INFO|VERBOSE|DEBUG|DEBUG1|DEBUG2|DEBUG3)
    • Kenster
      Kenster over 9 years
      Regarding the ps output, the netstat output, and the /var/run listing, are these listings from the computer you're trying to connect to, or the computer you're connecting from?
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' over 9 years
      Is the IP address correct? (You might have a stale DNS cache for some reason.) Is some option being applied through /etc/ssh/ssh_config or ~/.ssh/config? Post their content or try moving them out of the way.
    • Azuk
      Azuk over 9 years
      @Gilles, I edited my first post to put the outputs of the two config files you asked me. At first I had no config file in the ~/.ssh/config. I added this one as asked in a previous comment. You think I should move these files !?
  • Kanwar Saad
    Kanwar Saad about 9 years
    you are flushing all ip-table entries here. Instead of that just stop iptables by running "sudo service iptables stop"