Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically login via Windows 10 Open SSH client (pre-stored password)? [Putty or BitVise SSH is not an option!]

Recently our web hoster (Domainfactory) changed the method to externally access our online mysql database. From simple ssh "port forwarding" to a "unix socks tunnel".

The ssh call looks like this (and it works!):

ssh -N -L 5001:/var/lib/mysql5/mysql5.sock [email protected]

The problem: you have to enter the password every single time.

In the past I used BitVise SSH client to create a profile (which also stores the encrypted password). By simply double-clicking on the profile you'll be automatically logged in.

Unfortunately, neither the "BitVise SSH client" nor "Putty" (plink.exe) supports the "Unix socks tunnel" feature/extension, so I can't use these tools any more.

Does anyone have an idea how to realize an automated login (script, tool, whatever)?.

The employees who access the database must not know the SSH password in any case!

like image 226
berlinaut Avatar asked Oct 11 '25 18:10

berlinaut


1 Answers

I got a solution. The trick is to generate a SSH Key pair (private and public) on client side (Windows machine) calling ssh-keygen. Important: don't secure the ssh keys with a password (simply press [enter] if you're asked for a password, otherwise you'll be asked for the SSH-Key password every time you try to SSH). Two files will be generated inside C:\Users\your_user\.ssh\: id_rsa (private key) and id_rsa.pub (public key).

On server side create a .ssh directory within your user's home directory. Inside the .ssh directory create a simple text file called authorized_keys. Copy the contents of id_rsa.pub into this file (unfortunately ssh-copy-id isn't available yet for Windows. So you have to do the copy and paste stuff on your own.) Set permissions of authorized_keys file to 600.

Now you should be able to simply SSH into your server by calling [email protected] without entering a password. Create a batch file with your individual ssh-call and you're done.

Thanks to Scott Hanselman for his tutorial: https://www.hanselman.com/blog/how-to-use-windows-10s-builtin-openssh-to-automatically-ssh-into-a-remote-linux-machine

like image 61
berlinaut Avatar answered Oct 16 '25 08:10

berlinaut