安装必须的工具
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