普通登录
ssh -p 2211 root@140.206.185.170
# 使用默认端口22
ssh root@140.206.185.170
免密登录
先安装git
# 生成sshkey, 如果已经和github绑定过,则这一步不用执行
ssh-keygen
# 复制到目标服务器
ssh-copy-id root@192.168.0.106
# 等效于:cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
# 重启服务
service sshd restart
# 登录
ssh root@192.168.0.106
修改ssh登录端口
vim /etc/ssh/sshd_config
service sshd restart
SSH心跳
sudo vim /etc/ssh/sshd_config
# 每30秒向客户端发送一次心跳
ClientAliveInterval 30
ClientAliveCountMax 6
登录异常
找不到host key
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
解决(生成key):
sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
sudo ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
没有权限登录
$ ssh alvin@172.17.163.113
alvin@172.17.163.113: Permission denied (publickey).
解决方案:配置密码可以登录。
sudo sed 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config