超详细!linux环境git clone探坑录

简介: 超详细!linux环境git clone探坑录

一、背景



今天在linux上执行git clone git@bitbucket.org:xxxxxxxxx.git时,一直卡住不动,等了十几分钟之后出现如下的错误:


ssh: connect to host bitbucket.org port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.


意思是让我们检查repository是否存在,或者是否有权限访问这个repository。好吧,这个就是我创建的,怎么可能不存在呢?那就是权限的问题,那就配置ssh吧。


二、SSH配置



1. ssh目录不存在


[root@192 ~]# cd ~/.ssh
-bash: cd: /root/.ssh: No such file or directory


  1. 解决办法,执行如下命令
[root@192 ~]# ssh localhost


  1. 原因:.ssh 是记录密码信息的文件夹,如果没有登录过root的话,就没有 .ssh 文件夹,因此登录 localhost ,并输入密码就会生成了。


2. 如何配置Bitbucket的ssh


  1. 生成RSA算法的公私钥
[root@192 ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #这里是输入公私钥存放路径,默认就行-直接enter


  1. 输入私钥口令


[root@192 ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):  
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): #这里输入私钥口令
Enter same passphrase again: # 重复输入私钥口令
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
4c:80:61:2c:00:3f:9d:dc:08:41:2e:c0:cf:b9:17:69 emmap1@myhost.local 
The key's randomart image is:
+--[ RSA 2048]----+
|*o+ooo.          |
|.+.=o+ .         |
|. *.* o .        |
| . = E o         |
|    o . S        |
|   . .           |
|     .           |
|                 |
|                 |
+-----------------+


  1. 查看是否生成成功
[root@192 ~]# ls ~/.ssh 
id_rsa  id_rsa.pub


  1. 开启SSH代理服务器
[root@192 ~]# eval `ssh-agent` 
Agent pid 9700


  1. 添加密钥
$ ssh-add ~/.ssh/id_rsa


  1. 添加config文件
[root@192 ~]# cd ~/.ssh
[root@192 .ssh]# vim config


  1. config文件内容如下:
host bitbucket.org # git地址
 User git #登录名,这里需要填写你自己的,其它可以不改
 IdentityFile ~/.ssh/id_rsa #密钥路径


  1. 将公钥添加到Account settings

640.png


  1. 检验是否配置成功
[root@192 .ssh]# ssh -T git@bitbucket.org
logged in as BobTom
You can use git or hg to connect to Bitbucket. Shell access is disabled


3. 执行ssh -T git@bitbucket.org卡住


这里有可能是网络卡住的问题,解决办法如下:


vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
203.208.39.99 github.com
104.192.141.1 bitbucket.org


追加最后面一条就可以解决问题。


三、结果检验



[root@192 test]# ll
total 0
[root@192 test]# git clone git@bitbucket.org:BobJavacfox/car_wash_api.git
Cloning into 'car_wash_api'...
remote: Counting objects: 170, done.
remote: Compressing objects: 100% (80/80), done.
remote: Total 170 (delta 76), reused 142 (delta 67)
Receiving objects: 100% (170/170), 23.14 MiB | 3.10 MiB/s, done.
Resolving deltas: 100% (76/76), done.
[root@192 test]# ll
total 4
drwxr-xr-x. 7 root root 4096 Dec 10 00:12 car_wash_api
[root@192 test]#


执行速度超级快,而且不用每次都输入密码,是不是很方便。很有用是吧!!!


目录
相关文章
|
15天前
|
编解码 Linux
FFmpeg开发笔记(二十八)Linux环境给FFmpeg集成libxvid
XviD是开源的MPEG-4视频编解码器,曾与DivX一起用于早期MP4视频编码,但现在已被H.264取代。要集成XviD到Linux上的FFmpeg,首先下载源码,解压后配置并编译安装libxvid。接着,在FFmpeg源码目录中,重新配置FFmpeg以启用libxvid,然后编译并安装。成功后,通过`ffmpeg -version`检查是否启用libxvid。详细步骤包括下载、解压libxvid,使用`configure`和`make`命令安装,以及更新FFmpeg配置并安装。
33 2
FFmpeg开发笔记(二十八)Linux环境给FFmpeg集成libxvid
|
4天前
|
Linux 测试技术 开发工具
CentOS Linux 8使用阿里源(安装jdk11、git测试)
CentOS Linux 8使用阿里源(安装jdk11、git测试)
17 1
|
5天前
|
JavaScript Ubuntu Linux
蓝易云 - linux中安装nodejs,卸载nodejs,更新nodejs,git
请根据自己的Linux发行版和版本选择合适的命令。
13 2
|
6天前
|
开发工具 git
蓝易云 - 解决git clone时出现Failed to connect to 127.0.0.1 port 1573问题
希望这些信息能帮助你解决问题。如果问题仍然存在,可能需要检查你的网络设置或者联系你的网络管理员。
18 3
|
19天前
|
运维 Linux 网络安全
跨平台SSH文件传输:Linux与Windows环境下的实践指南
本文介绍了在Linux和Windows之间使用SCP、SecureCRT及PuTTY工具集进行文件传输的方法。在Linux中,利用SCP命令进行文件下载、上传及目录传输。在Windows环境下,PSFTP和PSCP提供类似功能,而SecureCRT作为SSH客户端,支持设置上传下载目录并进行文件传输。掌握这些工具的使用可提升跨平台运维效率。
|
17天前
|
Ubuntu Unix 大数据
【Linux操作系统】历史与环境
【Linux操作系统】历史与环境
【Linux操作系统】历史与环境
|
2天前
|
Oracle Java 关系型数据库
在Linux环境下采用压缩包方式安装JDK 13
在Linux环境下采用压缩包方式安装JDK 13
|
3天前
|
Linux Shell Python
linux服务器python2升级安装python3.7环境
linux服务器python2升级安装python3.7环境
8 0
|
5天前
|
NoSQL Linux 开发工具
【Linux】Linux环境基础开发工具_6
【Linux】Linux环境基础开发工具_6
10 0
|
5天前
|
小程序 Linux 开发工具
【Linux】Linux环境基础开发工具_5
【Linux】Linux环境基础开发工具_5
10 0