Forums

SSH tunnel to mysql has suddenly stopped working

We use ssh tunnel to save data to the pythonanywhere mysql database.

The code on our side hasnt changed for years, but since yesterday its stopped working with the below error message:

paramiko.ssh_exception.SSHException: Incompatible ssh peer (no acceptable host key) Could not connect to gateway ssh.pythonanywhere.com:22 : Incompatible ssh peer (no acceptable host key)

Any update on this?

We use SSH tunnel daily to update our site, so wanted to a get solution for this issue asap.

Thanks

Hi there -- you emailed us about this too, but as this might be generally useful I though it would be worth repeating our reply here for anyone else who's having the same problem.

Yesterday we did a system update that upgraded the operating system on the SSH machines, and they're now rejecting older types of keys that are no longer deemed secure by the OpenSSL development team. I also had an account with an out-of-date SSH key, and these are the steps I took to update it:

  • Locally: run "ssh-keygen -t rsa -b 2048 -E sha512" to get a new RSA keypair
  • Locally: run "ssh-keygen -t ed25519" to get an even better, more up-to-date Ed25519 keypair
  • I added the contents of the local files "~/.ssh/id_rsa.pub" and "~/.ssh/id_ed25519.pub" to the file "~/.ssh/authorized_keys" on PythonAnywhere.

That fixed the issue and meant that my SSH access was better-secured than it was before.

I have the same problem and could not understand what should I do? can you explain?

What did you not understand? Let us know, and we'll try to explain more precisely, if we can.

Thanks.. I need to run the code "ssh-keygen -t rsa -b 2048 -E sha512" in my local machine or in the console in pythonanywhere? after that what I need to copy to where? And nowadays i am using this code. with sshtunnel.SSHTunnelForwarder( ('ssh.pythonanywhere.com'), ssh_username=vpn_user, ssh_password=vpn_pass, remote_bind_address=(vpn_user+'.mysql.pythonanywhere-services.com', 3306) ) as tunnel:

        print("VPN Connected")

        connection = MySQLdb.connect(
            user=db_user,
            passwd=db_pass,
            host='127.0.0.1', 
            port=tunnel.local_bind_port,
            db=db_name,
        )

        print("MySQL Database connection successful")

What should I change? sorry about that but never worked with SSH? I was only using my username and pass.

Your code appears to be using password login, so you probably just need to update sshtunnel and maybe paramiko.

I am using this code and just not work.

# Paths to your private key files
private_key_path = r'C:\Users\fshigihara\.ssh\id_rsa'

sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0

with sshtunnel.SSHTunnelForwarder(
    ('ssh.pythonanywhere.com'),
    ssh_username=vpn_user,
    ssh_pkey=private_key_path,   
    remote_bind_address=(vpn_user+'.mysql.pythonanywhere-services.com', 3306)
) as tunnel:

print("VPN Connected")

To answer your previous question, you need to run the ssh-keygen command on your local machine. Then run: ssh-copy-id japanfelipe@ssh.pythonanywhere.com