cd ~/.ssh
ls
# config known_hosts
ssh-keygen
# Generating public/private rsa key pair.
#Enter file in which to save the key (/Users/huiqq/.ssh/id_rsa): ls
#Enter passphrase (empty for no passphrase):
# ...
# 最后有一个图像框 (randomart image)出现,结束
ls
# config known_hosts ls ls.pub
ssh-copy-id -i ls.pub pikapikaq@ip1 49.XXX. # 如果有指定端口号 要加 -p 不然会默认22号端口
# /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "ls.pub"
# /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
# /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
# 然后输入远程pikapikaq的密码...
# 之后就成功了
ssh-add -K ls # 把私钥加到 Keychain 服务中
# Identity added: ls (huiqq@HuiqingdeMacBook-Pro.local)
详细的SSH免密登录介绍
ssh-add
关于多对公私秘钥管理
设置了免密登录,如果想用密码登录
linux ssh设置了免密码登录,不取消免密码登录的前提下,如何用密码登录? -知乎
SSH自动断开
$ sudo vim ~/.ssh/config
# 找到 Host: Mango_V1,在其后添加:
ServerAliveInterval 60 # 每隔60s发送一个空包以保持连接
参考链接:解决ssh连接长时间不操作断开连接的问题