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.

这样的 就不用输入密码直接克隆了

posted @ 2018-03-09 15:58  迷失在路上  阅读(4504)  评论(0编辑  收藏  举报