参考:https://www.unixhot.com/article/33


在腾讯软件中心下载了git、TortoiseGit-2.10.0.0-64bit(原来在官网总下载到一半就没反应了)

简单安装后首先在gitbash里生成密钥(实现ssh免密码登录)

配置用户名

 git config --global user.name "a11"

配置邮箱

 git config --global user.email "[email protected]"

生成密钥对

 ssh-keygen -t rsa -C "[email protected]"

复制公钥到服务器的authorized_keys

 cat ~/.ssh/id_rsa.pub

docker exec -it 398558f43910 /bin/sh  (进入git容器)

vi ./.ssh/authorized_keys


git客户端使用

git clone [email protected]:/home/git/sample.git

git init

git remote add origin [email protected]:/home/git

git push -u origin master


问题:

测试克隆git上的目录总报没权限

git clone [email protected]:30813/home/git/sample.git

Cloning into 'sample'...

The authenticity of host '172.27.14.222 (172.27.14.222)' can't be established.

ECDSA key fingerprint is SHA256:FR1kBUsCE1Ng4hJFX6zt8nKZY8UKsU+LG0LU2mro2X0.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '172.27.14.222' (ECDSA) to the list of known hosts.

[email protected]'s password:

Permission denied, please try again.

[email protected]'s password:

Connection closed by 172.27.14.222 port 22

fatal: Could not read from remote repository.

原来对于服务器ssh非默认端口需要增加~/.ssh/config文件如下内容

Host:172.27.14.222

Port:30813

git clone [email protected]:/home/git/sample.git

Cloning into 'sample'...

The authenticity of host '[172.27.14.222]:30813 ([172.27.14.222]:30813)' can't be established.

ECDSA key fingerprint is SHA256:+NnZdk+KT0ipBcEJW65ryULNklH/Mb0L00hRVJhC8aQ.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '[172.27.14.222]:30813' (ECDSA) to the list of known hosts.

warning: You appear to have cloned an empty repository.