页面“Gogs搭建自己的git服务器”与“多个git账号之间的切换 多个git账号指定不同的key”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
docker>Evan
 
docker>Evan
(导入1个版本)
 
第1行: 第1行:
  
==官网==
+
多个git账号之间的切换 多个git账号指定不同的key
[https://gogs.io/ https://gogs.io/]
 
  
== Docker for Gogs==
+
ssh可以通过-i使用指定的私钥文件,如:
<pre>
 
母机
 
192.168.50.159
 
  
参考命令这里-d将容器跑到后台,不在当前终端输出
+
ssh -i ~/mykey_rsa username@host
#docker run --name=jenkins -it -u root -d -p 8080:8080 -p 50000:50000 -v /data/jenkins:/var/jenkins_home 3f08dc4f3f5d
 
  
# Pull image from Docker Hub.
+
但是走ssh协议的git却没有类似的参数可以指定,只能是使用用户默认的ssh私钥。
$ docker pull gogs/gogs
 
  
# Create local directory for volume. 物理机数据目录
+
而git 一般也是用key认证的,如果你来我一样的情形 ,怎么办 ? 先假设我有两个账号,一个是github上的,一个是公司gitlab上面的。先为不同的账号生成不同的ssh-key
$ mkdir -p /var/gogs
 
  
# Use `docker run` for the first time.
+
ssh-keygen  -t rsa -f ~/.ssh/id_rsa_work -C [email protected]
$ docker run --name=gogs -p 10022:22 -p 10080:3000 -v /var/gogs:/data gogs/gogs
 
  
# Use `docker start` if you have stopped it. 以后启动用这个命令就行了
+
然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_work和id_rsa_work.pub两个文件,id_rsa_work.pub文件里存放的就是我们要使用的key
$ docker start gogs
 
  
docker exec -it gogs /bin/bash
+
ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C [email protected]
  
http://192.168.50.159:10080/install
+
然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_github和id_rsa_github.pub两个文件,id_rsa_gthub.pub文件里存放的就是我们要使用的key
#用sqlite3 直接配置就行了,如果想要mysql 得自己搞一下喽 改为真实地址可以 pull push 但是不好看呢
 
  
 +
编辑 ~/.ssh/config,设定不同的git 服务器对应不同的key
  
域名 应用 URL 这些要改 为
+
在本机添加
192.168.50.159:10080
+
<pre>cat ~/.ssh/config
 
 
clone
 
 
 
git clone ssh://git@hostname:10022/username/myrepo.git
 
 
 
#注意  就是有很多地方 像新建的仓库地址显示为localhost 这个得改一下  还有 key 添加 无论在project 还是用户 哪里添加 都还是要密码 是glone 要指定用户名么
 
  
 +
Host github.com
 +
  hostname github.com
 +
  User git
 +
  #port 22
 +
  IdentityFile /home/evan/.ssh/id_rsa_github
 +
  IdentitiesOnly yes
 +
 
 
</pre>
 
</pre>
  
===参考===
+
#建一个gitlab别名,新建的帐号使用这个别名做克隆和更新
https://github.com/gogs/gogs/tree/master/docker
+
<pre>Host 192.168.11.11
 
+
  HostName 192.168.11.11
[https://www.jianshu.com/p/4e43bda3e1f2 使用Docker搭建git服务Gogs]
+
  User work
 
+
  IdentityFile ~/.ssh/id_rsa_work
[https://www.blackglory.me/docker-deploy-nginx-and-gogs/ 使用Docker部署Nginx + Gogs快速搭建在线Git服务]
 
 
 
[https://www.jianshu.com/p/75f2117a837c Docker部署(四):Gogs]
 
 
 
[https://github.com/helm/charts/tree/master/incubator/gogs helm gogs]
 
 
 
== 下载二进制包 ==
 
 
 
 
 
== 数据库相关操作 ==
 
<pre>#不用创建库 mysql -uroot -pevan < scripts/mysql.sql
 
  
create user 'gogs'@'localhost' identified by 'evan';
 
create user 'gogs'@'127.0.0.1' identified by 'evan';
 
grant all privileges on gogs.* to 'gogs'@'localhost' identified by "evan";
 
grant all privileges on gogs.* to 'gogs'@'127.0.0.1' identified by "evan";
 
flush privileges;
 
exit;
 
 
</pre>
 
</pre>
  
== 创建git 用户 ==
+
打开 [https://github.com/settings/ssh https://github.com/settings/ssh] 把pub key (id_rsa_github.pub) 添加一下
<pre>useradd git&nbsp;; passwd git&nbsp;</pre>
 
 
 
&nbsp;
 
 
 
 
 
 
 
 
 
== 配置启动文件 ==
 
<pre>cp scripts/init/centos/gogs /etc/init.d/ </pre>
 
 
 
#GOGS_HOME=/data/gogs/gogs
 
<pre>sed -i 's#GOGS_HOME=/home/git/gogs#GOGS_HOME=/data/gogs/#' /etc/init.d/gogs&nbsp;
 
 
 
mkdir -p /data/gogs/log;
 
 
 
chmod +x /etc/init.d/gogs
 
chown -R git:git /data/gogs/;
 
 
 
/etc/init.d/gogs start </pre>
 
 
 
#./gogs web
 
 
 
 
 
 
 
  
 +
  
== web 界面安装 ==
+
看到 You’ve successfully 就表示OK了
  mkdir -p /data/gogs-repositories &&&nbsp;chown -R git:git /data/gogs-repositories
 
  
[http://192.168.3.9:3000/install http://192.168.3.9:3000/install]<br/> ip:3000;
+
多个git账号之间的切换 也可以多个github 帐号 [http://memoryboxes.github.io/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/ http://memoryboxes.github.io/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/]
  
web 界面安装中要注意的&nbsp;
+
命令行下的git配置问题: 多个sshkey, 多个用户身份, git alias [http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/ http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/]
  
仓库根目录 &nbsp;/data/gogs-repositories
+
Git Config 命令查看配置文件 [https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/ https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/]
  
<br/> 服务器和其它服务设置 禁止用户自主注册&nbsp;<br/> 启用登录访问限制
+
ssh-keygen -t rsa -f ~/.ssh/id_rsa_evan -C [email protected]
  
 +
[https://www.linuxchina.net/?p=3393 https://www.linuxchina.net/?p=3393]
  
==  常见问题==
 
[https://gogs.io/docs/intro/faqs 官方常见问题]
 
 
&nbsp;
 
&nbsp;
  
 
&nbsp;
 
&nbsp;
  
[[Category:Git]]
+
[[Category:git]]

2017年1月23日 (一) 09:56的版本

多个git账号之间的切换 多个git账号指定不同的key

ssh可以通过-i使用指定的私钥文件,如:

ssh -i ~/mykey_rsa username@host

但是走ssh协议的git却没有类似的参数可以指定,只能是使用用户默认的ssh私钥。

而git 一般也是用key认证的,如果你来我一样的情形 ,怎么办 ? 先假设我有两个账号,一个是github上的,一个是公司gitlab上面的。先为不同的账号生成不同的ssh-key

ssh-keygen  -t rsa -f ~/.ssh/id_rsa_work -C [email protected]

然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_work和id_rsa_work.pub两个文件,id_rsa_work.pub文件里存放的就是我们要使用的key

ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C [email protected]

然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_github和id_rsa_github.pub两个文件,id_rsa_gthub.pub文件里存放的就是我们要使用的key

编辑 ~/.ssh/config,设定不同的git 服务器对应不同的key

在本机添加

cat ~/.ssh/config

Host github.com
  hostname github.com
  User git
  #port 22
  IdentityFile /home/evan/.ssh/id_rsa_github
  IdentitiesOnly yes
  
  1. 建一个gitlab别名,新建的帐号使用这个别名做克隆和更新
Host 192.168.11.11
  HostName 192.168.11.11
  User work
  IdentityFile ~/.ssh/id_rsa_work

打开 https://github.com/settings/ssh 把pub key (id_rsa_github.pub) 添加一下

ssh -vT [email protected]

看到 You’ve successfully 就表示OK了

多个git账号之间的切换 也可以多个github 帐号 http://memoryboxes.github.io/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/

命令行下的git配置问题: 多个sshkey, 多个用户身份, git alias http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/

Git Config 命令查看配置文件 https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/

ssh-keygen -t rsa -f ~/.ssh/id_rsa_evan -C [email protected]

https://www.linuxchina.net/?p=3393