9

I cannot ssh into my server from one of my Ubuntu installations, but if I use another Ubuntu installation or Windows operating system connecting with SSH works smoothly.

So something is broken in one of my Ubuntu installation and I'm struggling to find the exact problem.

I've tried reinstalling ssh/openssh-client/openssh-/ssh.

Here is few lines from verbose output :

ssh username@MYSERVERADDRESS -v
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to MYSERVER ([MYSERVERADDRESS]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
packet_write_wait: Connection to MYSERVERADDRESS port 22: Broken pipe

Tried many different solutions from googling but never worked any. Deleted .ssh directory, Deleted /etc/ssh/ssh_config (It was automatically created again with default values).

One more information is that problem isn't from server-side as I can SSH into server using another os and same network.

Update :

  1. Firewall disabled

  2. Server hosted on cloud

  3. I've 3 different machines with dual booted Windows and Linux.

  4. SSH working perfectly all machines except one in which Linux is troubling connection, and in same machine using Windows everything working fines.

  5. More clear view of point 4 : Total 3 machines each loaded with Linux and Windows (dual boot), and only one machine while running Linux having problem with SSH.

Let me know if you need more data from me (except SERVER ADDRESS and USERNAME).

13
  • 1
    Does the server have a firewall that is preventing the Ubuntu machine from connecting to port 22?
    – Kusalananda
    Commented Aug 31, 2017 at 6:03
  • Is username@MYSERVERADDRESS the same in all cases? Commented Aug 31, 2017 at 6:35
  • Is SERVERADDRESS a private IP address (such as one in the range 192.168.x.x), or a public address on the Internet? Commented Aug 31, 2017 at 6:40
  • Do both Ubuntus have the same /etc/ssh/ssh_config and ~/.ssh/config? Does the disconnect come immediately after you connect?
    – pfnuesel
    Commented Aug 31, 2017 at 7:41
  • 1
    Where do all machines stand physically? Are all on the same network? Could it be that IP addresses are clashing?
    – pfnuesel
    Commented Aug 31, 2017 at 8:13

3 Answers 3

8

I've found solution for this problem (sorry for answering my own question). I'm answering it because If someone has this problem then he/she can use solution that I found.

Actually problem is on both sides server as well as client side.

Server side problem was that /home/<user>/.ssh/known_hosts file on server was having invalid entry for Ubuntu installation as both operating system having same hardware id and same ip (static ip) but different keys.

So what I did is :

ssh-keygen -f /home/<user>/.ssh/known_hosts -R ip.ip.ip.ip

In my case ip.ip.ip.ip is static public ip of my network. Execute this command on both server as well as client machine where ip.ip.ip.ip will changed respectively.

I don't what this command does ( I found this solution from googling / trial-error)

You can also copy your client machines known_hosts file to other client machine or operating systems.

Sorry for my bad english.

And If anyone knows what this command does and why this command solved problem, then please tell us ! thank you.

Bingo solved!

1
  • Wow. Well caught. That's an excellent description. Do remember to accept it (when you can). Commented Sep 1, 2017 at 9:15
2

Locked out of your server? Get in right back!

Locked out of Server because of :

  • Host Key Verification Failed Error
  • SSH Bad Config
  • Bad Configuration
  • Firewall lock down

NOTE: This work for Unix | Linux, not on Windows.

Let's get started.

Two options available depending on your situation.

Opton 1 : Terminal Access ( if you can regain terminal access )

Terminal Access Option

Update your system with:

sudo aptitude update && aptitude safe-upgrade -y

*Or your may use:

sudo apt-get update && apt-get upgrade -y

Now reinstall you broken ssh

sudo apt-get --install ssh -y

You will install updated version!

To fix Host Key Verification Failed Error message, do:

ssh-keygen -R hostname

.

Blocked SSH Access? Get in right back!

If you are locked out completely from your server receiving time out when trying to connect using ssh due to; bad firewall configuration, blocked port, disk failure or wrong ssh config, Host Key Verification Failed Error etc. You will use Disk Mount option.

Disk Mount Option ( Remote Server )

Assuming that you've tried Remote Reboot, Remote Reset, Remote Hardware Reset via web interface and the problem persist.

Kindly ask your Data Center to give you a KVM-Console access and boot your box into a rescue mode ( you may get it for free for 1 hour )

From console access: Login:

*ubuntu@rescue#*

Mount your disk

    mkdir tempDisk

    mount --bind /dev/xvda2 /tempDisk
    mount --bind /proc /tempDisk/proc
    mount --bind /dev /tempDisk/dev
    mount --bind /sys /tempDisk/sys

    chroot /tempDisk

NOTE: Your prompt will change now you are in root

**root@your-host#**

Investigate the problem and fix it. Example update your system to fix potential error.

sudo apt-get update && apt-get upgrade -y
sudo apt-get --install ssh -y

Fix Host Key Verification Failed Error message with:

ssh-keygen -R hostname

Done exit back to DKM-Console prompt

`**root@your-host#** exit `

Bank in rescue

*ubuntu@rescue#*

Restart your server via same KVM-Console.

*ubuntu@rescue#* shutdown -r now

login back normal, and you're good to go.

Local Access Option

If you have local or rack access, remove your disk, mount it into another working linux of the same version, e.g:

***mytech@hostname#***

 mkdir tempDisk

mount --bind /dev/xvda2 /tempDisk
mount --bind /proc /tempDisk/proc
mount --bind /dev /tempDisk/dev
mount --bind /sys /tempDisk/sys

Get Access Back with: chroot /tempDisk

NOTE: Your prompt will change now you are in root of your server!

myServer@hostname#;

sudo apt-get update && apt-get upgrade -y
sudo apt-get --install ssh -y

Fix Host Key Verification Failed Error message with:

ssh-keygen -R hostname

Done exit

`**myServer@hostname#** exit `

Remove your disk and plug it back into the original server and turn her on!.

17
  • What evidence is there that the OP has is a broken version of SSH, please? Commented Sep 1, 2017 at 6:27
  • No SSH isn't broken, I'm sure about that as its working properly with other machines (or even on same machine but on different OS). Commented Sep 1, 2017 at 6:47
  • @MohanSharma so you can connect to it from other Windows Machine not from any linux machine? Commented Sep 1, 2017 at 9:00
  • @roaima if he can ssh in from other Windows machine, I don't think ssh is broken. Mohan should ssh in from Window, then just grade your system and re-install ssh, if the problem persist, check your local firewall rules to ALLOW ssh connect to port (if not default port) Commented Sep 1, 2017 at 9:08
  • 1
    I've already given an exact log from ssh in initial question. and your answer is still not valid as you're clearing known_hosts file which will again create same problem when I switch operating system on same machine. Thanks :D Commented Sep 2, 2017 at 16:53
-3

I'm not sure if my problem was exactly the same as yours but It was similar so I'll post my solution.

Preliminary information

  • I dual boot Ubuntu 20.04 and Windows 10
  • The system I am connecting from and to are on the same local network
  • I could not connect to my server from Ubuntu but I could with Windows 10 with putty

Now on to the solution, it was relatively simple.

So when I was attempting to connect to my server from Ubuntu I use this command ssh USER@SERVER_NAME and it just didn't work so I decided to find the local address of my server, I found this from my router. Then I tried this command ssh USER@SERVER_LOCAL_IP and it worked.

Hope this helps some one.

1
  • 2
    Judging by the accepted answer, your issue was nothing like the issue that the original poster had. Your issue is a DNS-related problem, while the other user had an issue relating to host certificates. Also note that the question shows that ssh is able to connect to the server, so the issues are totally unrelated.
    – Kusalananda
    Commented May 23, 2022 at 10:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .