On this page

SSH 免密码登陆 密钥登录

ssh-keygen命令生成密钥

$ ssh-keygen

上传ssh公钥

手动上传 (不推荐)
cat ~/.ssh/id_rsa.pub | ssh user@host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
$ chmod 644 ~/.ssh/authorized_keys
ssh-copy-id 自动上传公钥
$ ssh-copy-id -i id_rsa  [email protected]

ssh-agent ssh-add 命令

ssh-agent命令它让用户在整个 Bash 对话(session)之中,只在第一次使用 SSH 命令时输入密码,然后将私钥保存在内存中,后面都不需要再输入私钥的密码了
$ ssh-agent bash
使用ssh-add命令添加私钥
$ ssh-add  id_rsa

使用 ssh 命令正常登录远程服务器。

$ ssh  [email protected]

关闭密码登录

对于 OpenSSH,具体方法就是打开服务器 sshd 的配置文件/etc/ssh/sshd_config,将PasswordAuthentication这一项设为no。

$  vim /etc/ssh/sshd_config
PasswordAuthentication no

ssh 打字卡顿打字慢 ssh反应慢 使用 mosh

在客户端和服务器端都安装mosh

sudo apt install mosh

ufw allow 60000:60009/udp 

LC_ALL="en_US.UTF-8"    mosh --ssh="ssh -i ~/.ssh/codewhy "   [email protected]

VPS云服务器

digitalocean cloud digitalocean云计算

vultr cloud Vultr云计算