页面“Tcpdump”与“多个git账号之间的切换 多个git账号指定不同的key”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
docker>Evan
 
docker>Evan
(导入1个版本)
 
第1行: 第1行:
  
==tcpdump==
+
多个git账号之间的切换 多个git账号指定不同的key
<pre>
 
简介
 
用简单的话来定义tcpdump,就是:dump  traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具。 tcpdump可以将网络中传送的数据包的“头”完全截获下来提供分析。它支持针对网络层、协议、主机、网络或端口的过滤,并提供and、or、not等逻辑语句来帮助你去掉无用的信息。
 
  
Usage:
+
ssh可以通过-i使用指定的私钥文件,如:
  
-i interface
+
ssh -i ~/mykey_rsa username@host
-i  any,这个参数是监控所有的网络端口
 
  
host IP,监控指定IP的所有协议的数据包。
+
但是走ssh协议的git却没有类似的参数可以指定,只能是使用用户默认的ssh私钥。
-w 保存文件名
 
-s 包切片长度
 
-c 抓的包的数量。
 
</pre>
 
 
 
==tcpdump密码嗅探==
 
<pre>
 
在ftp server 监听 网卡eth0 上的 21 端口
 
  
tcpdump -i eth1 -nn -X 'port 21'
+
而git 一般也是用key认证的,如果你来我一样的情形 ,怎么办 ? 先假设我有两个账号,一个是github上的,一个是公司gitlab上面的。先为不同的账号生成不同的ssh-key
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
 
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
 
  
 +
ssh-keygen  -t rsa -f ~/.ssh/id_rsa_work -C [email protected]
  
在client login
+
然后根据提示连续回车即可在~/.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]
  
10:54:16.357663 IP 192.168.10.225.41624 > 192.168.30.56.21: Flags [P.], seq 21:31, ack 97, win 229, options [nop,nop,TS val 90850575 ecr 2797412999], length 10
+
然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_github和id_rsa_github.pub两个文件,id_rsa_gthub.pub文件里存放的就是我们要使用的key
0x0000:  4500 003e f19b 4000 3f06 9fb4 c0a8 0ae1  E..>..@.?.......
 
0x0010:  c0a8 1e38 a298 0015 df4f e322 519f d76e  ...8.....O."Q..n
 
0x0020:  8018 00e5 ece9 0000 0101 080a 056a 450f  .............jE.
 
0x0030:  a6bd 2287 5553 4552 2066 7470 0d0a      ..".USER.ftp..
 
  
 +
编辑 ~/.ssh/config,设定不同的git 服务器对应不同的key
  
10:54:16.358016 IP 192.168.10.225.41624 > 192.168.30.56.21: Flags [P.], seq 31:48, ack 131, win 229, options [nop,nop,TS val 90850575 ecr 2797412999], length 17
+
在本机添加
0x0000:  4500 0045 f19c 4000 3f06 9fac c0a8 0ae1  E..E..@.?.......
+
<pre>cat ~/.ssh/config
0x0010:  c0a8 1e38 a298 0015 df4f e32c 519f d790  ...8.....O.,Q...
 
0x0020:  8018 00e5 dc39 0000 0101 080a 056a 450f  .....9.......jE.
 
0x0030:  a6bd 2287 5041 5353 2065 7661 6e32 3233  ..".PASS.evan223
 
0x0040:  3335 350d 0a                            355..
 
  
可见 可见 ftp软件为 vsftp , ftp 用户 为 ftp 密码为 evan223355
+
Host github.com
 +
  hostname github.com
 +
  User git
 +
  #port 22
 +
  IdentityFile /home/evan/.ssh/id_rsa_github
 +
  IdentitiesOnly yes
 +
 
 
</pre>
 
</pre>
  
=例子=
+
#建一个gitlab别名,新建的帐号使用这个别名做克隆和更新
<pre>
+
<pre>Host 192.168.11.11
#自动生成分析文件  起因 连接 qq的相关业务老是timeout
+
  HostName 192.168.11.11
tcpdump  host  domain  -w tcp
+
  User work
 +
  IdentityFile ~/.ssh/id_rsa_work
  
 +
</pre>
  
抓取所有经过eth1,目的或源地址是192.168.1.1的网络数据
+
打开 [https://github.com/settings/ssh https://github.com/settings/ssh] 把pub key (id_rsa_github.pub) 添加一下
tcpdump -i eth1 host 192.168.1.1
 
  
指定源地址
+
ssh -vT git@github.com
tcpdump -i eth1 src host 192.168.1.1
 
  
指定目的地址
+
看到 You’ve successfully 就表示OK了
tcpdump -i eth1 dst host 192.168.1.1
 
</pre>
 
  
=参考=
+
多个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/]
  
[http://blog.linuxchina.net/?p=2454 大话tcpdump]
+
命令行下的git配置问题: 多个sshkey, 多个用户身份, git alias [http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/ http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/]
  
[http://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html Linux tcpdump命令详解]
+
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/]
  
[http://linuxwiki.github.io/NetTools/tcpdump.html tcpdump使用技巧]
+
ssh-keygen -t rsa -f ~/.ssh/id_rsa_evan -C evan886@gmail.com
  
[http://www.cnblogs.com/havenshen/p/3850167.html KeepAlive详解]
+
[https://www.linuxchina.net/?p=3393 https://www.linuxchina.net/?p=3393]
  
[http://blog.linuxchina.net/?p=3529 tcpdump密码嗅探]
+
&nbsp;
  
[http://blog.csdn.net/whuslei/article/details/6667471 TCP协议中的三次握手和四次挥手(图解)]
+
&nbsp;
  
[[category:ops]]  [[category:linux]]
+
[[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