在本地运行git bash(windows)
ssh-keygen -t rsa -C "xxx@qq.com"
一路回车
Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:/k7eBzEwIUHIjhq09GBEkoRMLKKbCV4XzyhHJ3ffsj0 vansenb@foxmail.com The key's randomart image is: +---[RSA 3072]----+ |%O o o+... | |O+. .++o oo | |= ..+O.. .o. | |o o.+oo +o. | |o+. + S +o | |+. . ..E | | . . .. | | + . . | | .+ .. | +----[SHA256]-----+
查看密钥文件
cat ~/.ssh/id_rsa.pub
从 ssh-rsa 开始,直到个人标识结束,全部复制
登陆到服务器(linux),将公钥写入文件
cd ~/.ssh && vim authorized_keys
使用 vim 编辑器打开文件后按 i 键进入编辑模式,使用键盘快捷键 Ctr V 粘贴刚才复制的公钥字符串。接着按 ESC 键进入 vim 编辑器的命令行模式,输入 :wq 并回车。
免密登陆
ssh root@10.1.1.1
第一次登陆提示
The authenticity of host '10.1.1.1 (10.1.1.1)' can't be established. ECDSA key fingerprint is SHA256:nGvmS+JKzQf1gG+Nzc0QN/qS6xSp1iV0rJFP1dILel4. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
输入yes即可
Warning: Permanently added '10.1.1.1' (ECDSA) to the list of known hosts. Last login: Wed Dec 23 21:43:28 2020 from 111.94.33.65 Welcome to Cloud Elastic Compute Service !