配置ssh密钥

每次用https往github上提交代码的时候,都需要输账号和密码,简直要疯了。还好我们有ssh这个神奇的家伙。我们可以首先在本地生成一个密码串,然后在github中添加进去,之后,就再提交的时候,就不用输繁琐的用户密码啦。下面,咱们一起开始吧~

1.配置Git 的 name 和email

1
2
git config --global user.name "vollen"
git config --global user.email "747133768@qq.com"

2.生成SSH密钥

1
ssh-keygen -t rsa -C "747133768@qq.com"

执行以上命令,连续确定,最后得到两个文件 id_rsa 和 id_rsa.pub

3.添加密钥到ssh

1
ssh-add filename

4.在github上添加ssh密钥

登陆github之后,在setting -> ssh key -> add ssh key

5.测试

1
ssh git@github.com

看到如下提示后,表示,配置成功

1
2
Hi lgfng! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.'

ssh 免密登陆服务器

生成秘钥

添加公钥到目标主机

将生成的公钥写入到目标主机的.ssh/authorized_keys 文件中.

配置本地ssh

修改.ssh/config文件

1
2
3
4
5
Host [服务器标识, 如vps]
Port [ssh 端口号, 默认是:22]
User [登陆用户名, 如root]
HostName [目标主机IP, 或者host]
IdentityFile [登陆使用的私钥:]

screen 命令ge

使用screen管理你的远程会话

##

ssh配置

可以指定不同远程服务器的: alias,ip,port,user, IdentityFile;
每一条记录如下:

1
2
3
4
5
Host vps1
Port 22
User ubuntu
HostName 54.238.193.131
IdentityFile ~/.ssh/id_rsa


配置ssh密钥
https://leafflow.top/2015/10/10/other/配置ssh密钥-2015-10-10/
作者
vollen
发布于
2015年10月10日
许可协议