git服務器 修改配置 添加公鑰


在未添加公鑰時, 克隆需要密碼輸入, 再編輯目錄下創建公鑰后就可以不用輸入密碼

在創建的目錄輸入創建公鑰命令    可以在計算機C:\Users\Administrator\.ssh 看到倆個文件

ssh-keygen -t rsa -C "358033733@qq.com"

創建完成后,

⑥ 服務器端 Git 打開 RSA 認證

進入 /etc/ssh 目錄,編輯 sshd_config,打開以下三個配置的注釋:

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile . ssh /authorized_keys
保存並重啟 sshd 服務:
[root@localhost ssh]# /etc/rc.d/init.d/sshd restart
[root@localhost git]# pwd    此git目錄就是你創建的遠程git庫
/home/git
[root@localhost git] # mkdir .ssh
[root@localhost git] # ls -a
. .. .bash_logout .bash_profile .bashrc .gnome2 .mozilla . ssh  在添加.ssh 后 git 目錄中也必要有其他的文件
然后把 .ssh 文件夾的 owner 修改為 git
[root@localhost git] # chown -R git:git .ssh
[root@localhost git] # ll -a
總用量 32
drwx------. 5 git git 4096 8月 28 20:04 .
drwxr-xr-x. 8 root root 4096 8月 28 19:32 ..
-rw-r--r--. 1 git git 18 10月 16 2014 .bash_logout
-rw-r--r--. 1 git git 176 10月 16 2014 .bash_profile
-rw-r--r--. 1 git git 124 10月 16 2014 .bashrc
drwxr-xr-x. 2 git git 4096 11月 12 2010 .gnome2
drwxr-xr-x. 4 git git 4096 5月 8 12:22 .mozilla
drwxr-xr-x. 2 git git 4096 8月 28 20:08 . ssh

回到 Git Bash 下,導入文件:

1
$ ssh  git@192.168.56.101 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

回到服務器端,查看 .ssh 下是否存在 authorized_keys 文件:

1
2
3
4
[root@localhost git] # cd .ssh
[root@localhost . ssh ] # ll
總用量 4
-rw-rw-r--. 1 git git 398 8月 28 20:08 authorized_keys

修改 .ssh 目錄的權限為 700

修改 .ssh/authorized_keys 文件的權限為 600

1
2
3
[root@localhost git] # chmod 700 .ssh
[root@localhost git] # cd .ssh
[root@localhost . ssh ] # chmod 600 authorized_keys

$ ssh git@47.95.220.203 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

git@47.95.220.203's password:

Administrator@2FH0EHDMX1PR88O MINGW64 ~/Desktop (master)

$ git clone git@47.95.220.203:/home/git/simple.git

Cloning into 'simple'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done.

這樣的 就不用輸入密碼直接克隆了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM