ubuntu安装并配置git工具

安装必须的工具

ca-certificates和openssh-server、openssh-client、git

apt-get  update

apt-get install -y --no-install-recommends ca-certificates openssh-server openssh-client git

git --version

配置SSH

第一种方式,使用账户以前已有的密钥
cp -r ./docker/.ssh  /root/.ssh
chmod 0600 /root/.ssh/id_rsa

eval $(ssh-agent)
ssh-add  /root/.ssh/id_rsa


第二种 创建新的密钥
#1)本地生成key
ssh-keygen -t rsa -C "email@**.com"
ssh-keygen -t rsa -C "diamond.account"
生成的密钥会在用户目录下的.ssh中
ubuntu的默认用户目录为 /root

在这里插入图片描述

生成的密钥在 .ssh文件夹下
# cd ~
# pwd
/root
# ls -a
.  ..  .bashrc  .profile	 .ssh
#cd .ssh
# ls -a
.  ..  aaa  aaa.pub


#2)查看生成的key 
 cat  ~/.ssh/aaa.pub

#3)在github个人账户配置key


配置用户

运行以下命令配置用户信息
 git config --global user.name "username"        
 git config --global user.email "email@**.com"  
 git config --global credential.helper store
 git config user.name                                           
 git config user.email    

查看用户                                       
# git config --list
user.name=username
user.email=email@**.com
credential.helper=store

其实,配置完成后在用户目录会生成 .gitconfig文件,用户存储配置的用户信息:
# cd ~
# ls -a
.  ..  .bashrc	  .gitconfig  .profile	 .ssh

 查看.gitconfig文件内容:
# cat .gitconfig
[user]
	name = username
	email = email@**.com
[credential]
	helper = store

使用

例如:克隆公司的项目
git clone https://rephost/**/**.git 
一般访问的都是公司的gitlab,所以这里就不说怎么建仓库了。

第一次使用的时候需要输入用户名和密码,并会在 用户目录下生成.git-credentials文件
# ls -a
.  ..  .bashrc	.git-credentials  .gitconfig  .profile	.ssh

文件内容如下
#cat .git-credentials
https://{username}:{password}@gitlab.bj.sensetime.com
生成了这个文件,以后使用git的时候就不需要输入密码了

以后就不用输入了,所有如果想要第一次也不用输入用户名密码的话,可以自己手动创建该文件,并写入
https://{username}:{password}@{rephost}

上面的rep时你的仓库的host,对应地址里的rephost
git clone https://rephost/**/**.git 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值