Setup SFTP to use public-key authentication

前端 未结 3 957
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 10:46

How do you setup server to server SFTP to use public-key authentication instead of user account and password?

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-20 11:14

    This is a solution for windows users

    I had a similar issue on windows so I used Putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

    If you need to generate a public key then use: http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe

    Then, when you want to automate a batch to download from the FTP server the Pageant in order to load the private key into session http://the.earth.li/~sgtatham/putty/latest/x86/pageant.exe

    Then use the PSFTP to connect and perform actions http://the.earth.li/~sgtatham/putty/latest/x86/psftp.exe

    So here is sample code for the batch:

    !--Loading the key to session--!
    @C:\pageant.exe "C:\privatekey.ppk"
    !--Calling the PSFTP.exe with the uaser and sftp address + command list file--!
    @C:\psftp user@your.server.address -b C:\sftp_cmd.txt
    

    Command list file (sftp_cmd.txt) will like like this:

    mget "*.*" !--downloading every thing
    !--more commands can follow here
    close
    

    Now, all you need to to schedule it in scheduled tasks *I wish it was simple as unix's cron job....

提交回复
热议问题