1.安裝githtml
sudo apt-get install git
2.建立git用戶,運行git服務git
sudo adduser git
3.建立證書登陸vim
建立/home/git/.ssh/authorized_keys文件windows
$ cd /home/git/ $ mkdir .ssh $ chmod 700 .ssh $ touch .ssh/authorized_keys $ chmod 600 .ssh/authorized_keys
收集全部須要登錄的用戶公鑰,公鑰位於id_rsa.pub文件中,把咱們的公鑰導入的/home/git/.ssh/authorized_keys文件裏,一行一個。服務器
4.初始化git倉庫,建立目錄,切換目錄擁有着。app
$ cd /home $ mkdir depot ##建立目錄depot $ chown git:git depot/ ##將depot的擁有者修改成git $ cd depot $ git init --bare test.git ##初始化test.git倉庫 $ chown -R git:git test.git ##把倉庫所屬用戶改成git
5.上面已經搭建好了git服務器,如今在windows上,將代碼clone到本地。ssh
$ git clone git@172.16.1.130:/home/depot/test.git Cloning into 'test'... The authenticity of host '39.106.197.158 (39.106.197.158)' can't be established. ECDSA key fingerprint is SHA256:GVUeRnxfWunh7Vv18IpL2UoW/zOXWBlWKfgklpruQ48. Are you sure you want to continue connecting (yes/no)? yes ## 這裏選擇yes Warning: Permanently added '39.106.197.158' (ECDSA) to the list of known hosts. git@172.16.1.130's password: ##輸入你建立的git用戶的密碼 warning: You appear to have cloned an empty repository.
6.在clone下來的本地倉庫裏,建立文件,並上傳到遠端倉庫。測試
在clone下來的test文件中建立test.txt文件,將文件添加至暫存區,而後再提交到遠端倉庫.net
git add test.txt ##將文件添加的暫存區 git commit -m '測試提交' ##將文件提交至遠端倉庫 -m後面是本次提交說明
7.到這裏咱們發現本身的私鑰並無讓本身免登錄,這時須要配置sshd_config文件並重啓sshdcode
1. su root ;sshd_config位於/etc/ssh/ 文件夾下,須要使用root權限,同時若是出現 could not load host key: rsa_key dsa_key ecdsa_key, 也是因爲這個緣由,由於這三個文件只有root用戶擁有讀權限。 2. vim sshd_config 3. 取消AuthorizedKeysFile的註釋,並修改成 AuthorizedKeysFile /home/git/.ssh/authorized_keys 4.重啓sshd : /usr/sbin/sshd
若是重啓sshd時,出現Could not load host key: /etc/ssh/ssh_host_ed25519_key則執行下面的命令
ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key
生成ssh_host_ed25519_key文件
再次執行sshd重啓成功
參考博客:https://www.cnblogs.com/ToDoToTry/p/3956687.html
http://www.xitongzhijia.net/xtjc/20150615/50836.html