设置 SFTP 以使用公钥身份验证

发布于 2024-08-21 05:46:10 字数 44 浏览 9 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

橘味果▽酱 2024-08-28 05:46:10

在客户端中,您需要生成其公钥并将其添加到服务器的授权密钥列表中。

以下是您可以使用的命令。

在客户端计算机上

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

在服务器上

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

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
握住你手 2024-08-28 05:46:10

记住

chmod 700 .ssh

还有

chmod 600 authorized_keys

Remember to

chmod 700 .ssh

and also

chmod 600 authorized_keys
多情出卖 2024-08-28 05:46:10

这是针对 Windows 用户的解决方案

,我在 Windows 上遇到了类似的问题,所以我使用了 http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

如果您需要生成公钥,请使用:
http://the.earth.li/~sgtatham/putty/latest /x86/puttygen.exe

然后,当您想要自动批量从 FTP 服务器下载 Pageant 以便将私钥加载到会话中时
http://the.earth.li/~sgtatham/putty/latest /x86/pageant.exe

然后使用 PSFTP 连接并执行操作
http://the.earth.li/~sgtatham/putty/latest /x86/psftp.exe

所以这里是批处理的示例代码:

!--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 [email protected] -b C:\sftp_cmd.txt

命令列表文件(sftp_cmd.txt)将像这样:

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

现在,您需要在计划任务中安排它
*我希望它像 unix 的 cron 工作一样简单......

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 [email protected] -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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文