5

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 no-more-sessions@openssh.com
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).

  • 1
    Does the server have a firewall that is preventing the Ubuntu machine from connecting to port 22? – Kusalananda Aug 31 '17 at 6:03
  • Is username@MYSERVERADDRESS the same in all cases? – roaima Aug 31 '17 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? – roaima Aug 31 '17 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 Aug 31 '17 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 Aug 31 '17 at 8:13
4

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!

  • Wow. Well caught. That's an excellent description. Do remember to accept it (when you can). – roaima Sep 1 '17 at 9:15
1

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!.

  • What evidence is there that the OP has is a broken version of SSH, please? – roaima Sep 1 '17 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). – Mohan Sharma Sep 1 '17 at 6:47
  • @MohanSharma so you can connect to it from other Windows Machine not from any linux machine? – Prince Adeyemi Sep 1 '17 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) – Prince Adeyemi Sep 1 '17 at 9:08
  • @LasVegasCoder Not exactly, I was able to ssh into server from linux machine also. Suppose you are having two machine A, B. A is cloud vps and B is client (anywhere in world). Now in machine B user installed two different operating systems linux and windows. When that user tried to ssh into server from windows (machien B) it worked perfectly but when tried from linux (machine B) command shown broken pipe error. – Mohan Sharma Sep 1 '17 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.