Debian SFTP自动登录配置指南
一 核心思路
二 快速配置步骤
ssh-keygen -t rsa -b 4096ssh-copy-id user@remote_hostsudo nano /etc/ssh/sshd_configPubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keyssudo systemctl restart sshsftp user@remote_host三 权限与目录安全检查
chmod 600 ~/.ssh/id_rsachmod 644 ~/.ssh/id_rsa.pubchmod 700 ~/.sshchmod 755 ~(属主为该用户)chmod 700 ~/.sshchmod 644 ~/.ssh/authorized_keys四 自动化与脚本使用建议
eval "$(ssh-agent -s)"ssh-add ~/.ssh/id_rsasftp无需再次输入口令,适合定时任务与脚本。sftp -i ~/.ssh/id_rsa user@remote_host-o StrictHostKeyChecking=no来跳过验证,存在中间人攻击风险;如确需非交互,可预先分发并记录指纹。五 常见故障排查
/etc/ssh/sshd_config中PubkeyAuthentication yes与AuthorizedKeysFile路径是否正确,修改后执行:sudo systemctl restart ssh/etc/ssh/sshd_config):
Subsystem sftp internal-sftpMatch User www-data
ChrootDirectory /sftp/www-dataForceCommand internal-sftpPermitTTY noX11Forwarding noAllowTcpForwarding nosudo sshd -t,再重启:sudo systemctl restart sshsudo tail -f /var/log/auth.log~/.ssh/known_hosts写入目标主机指纹,或在受控环境下预先分发指纹以避免交互。