**自动密码连接,**通过本地生成`SSH密钥对`实现,
ssh-keygen -t rsa -b 4096生成私钥和公钥文件。将公钥文件(hbssh.pub)复制到服务端内,
sudo cat hbhost.pub > ~/.ssh/authorized_keys将公钥内容复制到authorized_keys文件中后,再打开其sshd_config文件,添加
AuthorizedKeysFile .ssh/authorized_keys接着设置权限
chmod 600 ~/.ssh/authorized_keyschmod 700 ~/.sshpowershell本地添加私钥文件
加载个人及系统配置文件用了 3982 毫秒。(base) PS C:\Users\28581_000> Get-Service ssh-agent | Set-Service -StartupType Automatic(base) PS C:\Users\28581_000> Start-Service ssh-agent(base) PS C:\Users\28581_000> Get-Service ssh-agent
Status Name DisplayName------ ---- -----------Running ssh-agent OpenSSH Authentication Agent
(base) PS C:\Users\28581_000> ssh-add "D:\program\CustomConfigInfo\ssh\hbssh"Enter passphrase for D:\program\CustomConfigInfo\ssh\hbssh:Identity added: D:\program\CustomConfigInfo\ssh\hbssh (shavi\shavi@shavi)(base) PS C:\Users\28581_000>登录测试。
# -vvv 用于显示信息ssh -vvv -i D:\program\CustomConfigInfo\ssh\hbssh mtxl@8.130.90.22如果仍要密码登录,有两个原因,一是服务端的配置未正确,二是本地未设置正确。
ssh 长时无操作自动断开,这可以通过.ssh/config的修改来解决,打开并添加
# windows 下 .ssh/config,linux下为/etc/ssh/sshd_configClientAliveInterval 60ClientAliveCountMax 86400ssh(OpenSSH_for_Windows)-CSDN博客
OpenSSH for Windows 中基于密钥的身份验证 | Microsoft Learn
来源:CSDN 原文,首次发布于 2024-08-29。