Mac默认是安装了ssh工具软件的。

先用mac的 终端工具生成 id_rsa 和id_rsa.pub 秘钥,生成方式如下:

1、当前用户目录下,检查SSH公钥

 cd ~/.ssh

看看存不存在.ssh,如果存在的话,掠过下一步;不存在的请看下一步

2、生成SSH公钥,一路next,密码设为空

$ ssh-keygen -t rsa -C "[email protected]" 

# Creates a new ssh key using the provided email Generating public/private rsa key pair. 

Enter file in which to save the key (/home/you/.ssh/id_rsa):

现在你可以看到,在自己的目录下,有一个.ssh目录,说明成功了

3、然后在.ssh中可以看到

xxx-MacBook-Pro:.ssh xxx$ cd .ssh

xxx-MacBook-Pro:.ssh xxx$ ls

config id_rsa id_rsa.pub known_hosts

xxx-MacBook-Pro:.ssh xxx$ pwd

/Users/xxx/.ssh

4、添加SSH公钥到github

打开github,找到账户里面添加SSH,把id_rsa.pub内容复制到key里面(注意使用cat id_rsa.pub查看,以防有空格)。

5 测试是否生效

使用下面的命令测试

ssh -T [email protected]

当你看到这些内容放入时候,直接yes

The authenticity of host 'github.com (207.97.227.239)' can't be established. 

RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. 

Are you sure you want to continue connecting (yes/no)?

看到这个内容放入时候,说明就成功了。

Hi username! 

You've successfully authenticated, but GitHub does not provide shell access.

6、下面是使用代理的方式登录linux远程服务器:ssh [email protected] 

如果报错,说明id_rsa.pub没有同步到远程linux服务器,linux服务器检查是否有"[email protected]"

的id_rsa.pub秘钥(cat看到的内容)。有的话就可以登录。

7.如果还是登录不了,在.ssh目录下创建config文件。输入如下内容:

xxx-MacBook-Pro:.ssh xxx$vim config

Host *

  ForwardAgent yes 

  PasswordAuthentication yes 

  StrictHostKeyChecking no

  HashKnownHosts yes 

  Compression yes 

  ServerAliveInterval 60

保存退出,重新登录即可。。。