1. windows下安装msysgit
2. 生成rsa秘钥,位置可选择默认位置默认名字(或者自己指定位置后续通过配置文件配置),秘钥可以略过,一路按enter
ssh-keygen -t rsa -C "youremail@yourcompany.com"
ssh的默认寻找的路径是 ~/.ssh
3.把生成的一对秘钥中的公钥(*.pub)放到服务器上
4.第一次连接到服务器上的时候可能会提示如下信息
The authenticity of host 'mint.phcomp.co.uk (78.32.209.33)' can't be established. RSA key fingerprint is 6a:de:e0:af:56:f8:0c:04:11:5b:ef:4d:49:ad:09:23. Are you sure you want to continue connecting (yes/no)? nofingerprint是服务端的公钥的摘要,是让你确定你是否要连接到该服务器,确定的话输入yes,否则输入no。这是为了避免中间人攻击
第一连接后将生成一个known_hosts,记录已经连接过的服务器。
如果处于某种正常原因(如服务器的ip地址变化了),再次进行连接时,会出现如下信息
某天机器又改IP了,ssh后,报:
mmt@FS01:~$ ssh -o StrictHostKeyChecking=no 192.168.0.130
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
fe:d6:f8:59:03:a5:de:e8:29:ef:3b:26:6e:3d:1d:4b.
Please contact your system administrator.
Add correct host key in ~/.ssh/known_hosts to get rid of this message.
Offending key in ~/.ssh/known_hosts:38
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
Permission denied (publickey,password).
注意这句
Add correct host key in ~/.ssh/known_hosts to get rid of this message.
可以在known_hosts文件中删除关于该主机地址的记录
参考文章
http://blog.youkuaiyun.com/kimsoft/article/details/5865418
http://xuyuan923.github.io/2014/11/04/github-gitlab-ssh/
http://www.phcomp.co.uk/Tutorials/Unix-And-Linux/ssh-check-server-fingerprint.html