简体   繁体   English

设置SFTP以使用公钥验证

[英]Setup SFTP to use public-key authentication

如何设置服务器到服务器SFTP以使用公钥验证而不是用户帐户和密码?

In the client you need to generate its public key and add it to server's authorized key list. 在客户端中,您需要生成其公钥并将其添加到服务器的授权密钥列表中。

The following are the commands you can use. 以下是您可以使用的命令。

On client machine 在客户端机器上

ssh-keygen -t dsa -f id_dsa
mv id_dsa* ~/.ssh/
scp ~/.ssh/id_dsa.pub USER_NAME@SERVER:~/.ssh/HOST_NAME.key

On the server 在服务器上

cat ~/.ssh/HOST_NAME.key >> ~/.ssh/authorized_keys2

Remember to 记得

chmod 700 .ssh

and also 并且

chmod 600 authorized_keys

This is a solution for windows users 这是Windows用户的解决方案

I had a similar issue on windows so I used Putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html 我在Windows上有类似的问题所以我使用了来自http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html的 Putty

If you need to generate a public key then use: http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe 如果您需要生成公钥,请使用: 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 然后,当您想要自动批量从FTP服务器下载Pageant,以便将私钥加载到会话中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 然后使用PSFTP连接并执行操作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: 命令列表文件(sftp_cmd.txt)将如下所示:

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.... 现在,您只需要在计划任务中安排它*我希望它像unix的cron作业一样简单....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM