Search code examples
linuxazurecygwinsftpazure-virtual-machine

SFTP RSA authentication in Azure VM


Requirement- Connecting SFTP server from local windows machines using WinSCP with keys

Technical- I have Azure VM(Windows 2012 server R2) in which Cygwin64 is installed for SFTP. I want to connect SFTP server using RSA authentication i.e using keys.

I have edited the sshd_config file for RSA authentication. In cygwin64 folder I have also created .ssh folder and under that Authorized_keys file.

From local machine using putty I have generated Public and private keys and this public key I have entered in Authorized keys file but when I am trying to connect with that Private key it is saying "Server refused our key"


Solution

  • I have entered in Authorized keys file but when I am trying to connect with that Private key it is saying "Server refused our key"

    If you see this type of message, the first thing you should do is check your server configuration carefully. Common errors include having the wrong permissions or ownership set on the public key or the user’s home directory on the server.

    Maybe you can follow those steps to setup CYGWIN authenticate with private key:
    1.Install GYCWIN (OpenSSH and cygrunsrv)
    2.configure sshd use this command ssh-host-config -y
    3.Start SSHD service with this command cygrunsrv --start sshd
    4.Add your public key to authorized_keys(we can copy public Key to this file):

    jason@jasonvm ~/.ssh
    $ ls -a
    .  ..  authorized_keys  id_rsa  id_rsa.pub  id_rsa1  known_hosts
    $ cat authorized_keys 
    ssh-rsa AAAAB3Nxxx.......xxxxzaAVbeVFw==
    jason@jasonvm ~/.ssh
    $ pwd
    /home/jason/.ssh
    

    By the way, if you can't find this directory, you can use ssh-keygen.exe command to create this directory /home/user/.ssh, if you can't find this file authorized_keys, we should create it, and run this command chmod 600 authorized_keys

    Afther that, we can use other Linux VM to SSH or SFTP this VM(we should open port 22 on Azure NSG inbound rules).
    If you want to use winscp to login this VM, we should convert private key to .ppk. In this way, we can use this key to login this SFTP.

    Note:
    we can use winscp to convert .key to .ppk.enter image description here

    For test, you may try to use Putty to login azure vm with your private key, to make sure you are using the right private key and public key.

    Update:
    We can add open ssh and sftp like this:enter image description hereenter image description hereenter image description here