Debian SSH 客户端配置指南
一 安装与检查
ssh -Vsudo apt-get update && sudo apt-get install openssh-client二 生成密钥与免密登录
ssh-keygen -t ed25519 -C "your_email@example.com"ssh-keygen -t rsa -b 2048 -C "your_email@example.com"ssh-copy-id -i ~/.ssh/id_ed25519.pub username@server_ip -p 2222ssh-copy-id 不可用,可手动将公钥内容追加到服务器 ~/.ssh/authorized_keys。mkdir -p ~/.ssh && chmod 700 ~/.sshtouch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keysssh username@server_ip -p 2222,若配置正确将以密钥完成认证。三 客户端配置文件 ~/.ssh/config 示例
Host myserver
HostName server_ip_or_domain
Port 2222
User username
IdentityFile ~/.ssh/id_ed25519
ServerAliveInterval 60
StrictHostKeyChecking no # 仅测试环境使用,生产建议保持默认 yes
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_github
IdentitiesOnly yes
ssh myserver、git clone git@github:owner/repo.git。如需指定自定义配置文件:ssh -F /path/to/ssh_config hostname。四 常用客户端选项与文件传输
ssh -p 2222 user@hostssh -C user@hostssh -v(可叠加 -vv、-vvv)ssh -i ~/.ssh/id_ed25519 user@hostssh -X user@hostscp -P 2222 /local/file user@host:/remote/dirscp -P 2222 user@host:/remote/file /local/dir五 常见问题与排查
chmod 600 ~/.ssh/id_ed25519chmod 700 ~/.sshStrictHostKeyChecking no,或首次连接时手动确认并写入 known_hosts。sudo systemctl status sshsudo ufw allow 2222/tcp 或 sudo firewall-cmd --permanent --add-port=2222/tcp && sudo firewall-cmd --reloadPubkeyAuthentication yes、PasswordAuthentication no),且已将你的公钥加入 authorized_keys。