ssh自动登陆

本文刻录一些登陆的操作。

ssh密钥登陆Linux服务

环境:windows+git bash+mingw
服务器:Linux CentOS 7
打开git bash,产生密钥对:

1
ssh-keygen -t rsa -b 4096

出现Enter passphrase (empty for no passphrase)时,直接回车。
最后输出目录:

1
2
Your identification has been saved in /c/Users/Late Lee/.ssh/id_rsa.
Your public key has been saved in /c/Users/Late Lee/.ssh/id_rsa.pub.

进入cd /c/Users/Late\ Lee/.ssh/目录。拷贝公钥到Linux服务器。

1
ssh-copy-id -i id_rsa.pub root@45.21.35.234

输出信息:

1
2
3
4
5
6
7
8
9
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.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
root@45.21.35.234's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'root@45.21.35.234'"
and check to make sure that only the key(s) you wanted were added.

输入ssh root@45.21.35.234,可以不需要密码登陆。