

指定ssh key访问git
source link: https://www.cnblogs.com/MikeZhang/archive/2012/11/27/gitWithSshKey_20121127.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

最近在用git,感觉每次输入密码很不方便,想借助ssh key来实现(一种类似ssh命令中-i参数的机制)。现在问题解决了,这里总结下(从建库开始),也方便我以后查阅。
建立一个私有仓库
这里以test1目录示例:
1、创建test1文件夹
mkdir test1 cd test1
2、git初始化
git init .
3、添加文件
touch readMe.txt git add . git commit -m "init"
4、导出"祼仓库"
cd .. git clone --bare test1/.git test1.git
产生ssh key
cd ~/.ssh ssh-keygen -t rsa -b 4096 #输入文件名称保存即可,比如:id_rsa_test1
导入ssh key
将上一步骤产生的公钥导入authorized_keys中 cat id_rsa_test1.pub >> authorized_keys
ssh访问测试
将私钥通过安全方式copy到其它主机的特定目录(比如tmp),执行如下命令(192.168.1.100为目的主机的ip地址):
ssh 192.168.1.100 -i /tmp/id_rsa_test1
git访问测试(指定ssh key)
linux配置
1、安装git(CentOS6 环境)
yum install git -y
2、配置config文件
cd ~/.ssh/
vi config
添加如下代码(192.168.1.100为git服务器ip):
Host host100 Hostname 192.168.1.100 User root IdentityFile /tmp/id_rsa_test1
3、git访问
配置完成后,通过以下命令访问,都无需密码:
git clone host160:/tmp/test1.git cd test1 git pull git push
windows配置
1、安装git
网址:http://git-scm.com/downloads (我安装的版本为:Git-1.8.0-preview20121022,下载链接:http://cloud.github.com/downloads/msysgit/git/Git-1.8.0-preview20121022.exe)
tips:安装时如果选择“Run Git and included Unix tools from the Windows Command Prompt.”选项的话可以在命令行中直接用git及unix命令。
2、配置config文件
这个和linux差不多,也是在用户目录的".ssh"文件夹,比如(windows XP下):
C:\Documents and Settings\Administrator.ssh
建立config文件,其它的仿照linux的操作配置好主机和key。
3、git访问 操作和linux环境下相同。
本文github地址:
https://github.com/mike-zhang/mikeBlogEssays/blob/master/2012/20121127_指定sshKey访问git.rst
Recommend
-
16
git clone 指定 ssh-key 其实我们往往会遇到这样一个问题 打个比方: 公司邮箱是:[email protected] 个人邮箱:[email protected] & [email protected] 我们分别有:公司git仓库 / github仓库...
-
8
【转载】限制Linux指定用户访问某个文件夹,禁止其访问指定文件夹 发表于 20...
-
19
Introduction If you are using SSH keys with Git to clone and pull your repositories, you may have to manage several SSH keys. For example, it is common to setup a "deploy key" in GitHub (Repository | Settings | Deploy Keys
-
12
设置Linux系统SSH-KEY访问方式设置 作者: wencst 分类: linux,Uncategorized 发布时...
-
11
如何通过HTTP协议访问指定版本的SVN库内容 在汇总晨检报告时,有同事反馈提交的内容被覆盖了,需要从某个指定版本中取出被覆盖的内容。 然而我在跳板机上只能通过HTTP协议用浏览器访问SVN仓库,默认访问的是最新版本内容。 那么要如...
-
11
centos学习 ssh 远程登陆指定端口 2021-05-30 ssh 到指定端口 ssh -p xx user@...
-
10
V2EX › 程序员 求助,客户端访问数据库怎么指定端口号 shenxj · 22 小时 11 分钟前 · 616...
-
12
Using special SSH key for Git Jul 23, 2019 In ~/.ssh/config: host github.com HostName github.com IdentityFile ~/.ssh/id_rsa_github User git
-
8
Signing Git Commits with Your SSH Key November 15, 2021 You may already be signing your Git commits with a
-
6
首先做个说明生成一对默认的私钥公钥,私钥自己客户端留着用,公钥可以给多个平台用。多对私钥公钥,主要是应对一个平台多个账号的情况。当然你想每个平台使用不同的私钥公钥也是可以的。多次生成私钥公钥需要自己重新命名,否则会覆...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK