码迷,mamicode.com
首页 > 其他好文 > 详细

centos 7 安装git 免密登录

时间:2018-11-13 16:13:38      阅读:900      评论:0      收藏:0      [点我收藏+]

标签:strong   family   改变   本地   mini   https   com   too   microsoft   

第一步.安装git服务

yum  install git

第二步.创建git用户

adduser git

第三步生成git登录公钥

安装完成 git客户端之后,本地CMD中执行

git config --global user.name "你的名字"
git config --global user.email "你的邮箱"

一路回车,生成用户公钥文件(id_rsa.pub)

ssh-keygen -t rsa -C "你的邮箱"

若未改变目录,到 C:\Users\Administrator\.ssh\id_rsa.pub 找到.ssh目录下的id_rsa.pub文件,使用notepad++或其他软件打开,复制其中全部内容,待加入到服务器的authorized_keys 文件内

第四步 设置免密码登录

收集所有需要登录的用户的公钥(id_rsa.pub)文件,把所有公钥导入到 authorized_keys 文件内,一行一个。

 

authorized_keys的位置是在:如果你创建了用户username,那该文件应该创建在/home/username/.ssh/authorized_keys;如果你使用的是root用户,该文件应该创建在~/.ssh/authorized_keys(即root/.ssh/authorized_keys)。

cd /home/git
mkdir .ssh
vi authorized_keys

如果保存提示 E212

E212: Cant open file for writing
Press ENTER or type command to continue

退出编辑之后执行 ssh localhost 之后重新编辑 authorized_keys

ssh localhost

设置权限

chmod 700 /home
chmod 700 /home/git
chmod 700 /home/git/.ssh
chmod 600 /home/git/.ssh/authorized_keys
chown git /home
chown git /home/git
chown git /home/git/.ssh
chown git /home/git/.ssh/authorized_keys

第五步初始化git仓库

cd /usr
mkdir git
cd git
git init --bare test.git
chown -R git:git test.git

第六步禁用shell登录

禁用shell登录:
处于安全的考虑,第二步创建的git用户不允许登录shell,这可以通过编辑 /etc/passwd 文件完成。

git:x:1003:1003::/home/git:/bin/bash

改为

git:x:1003:1003::/home/git:/usr/bin/git-shell

这样,git用户可以正常通过ssh使用git,但无法登录shell,因为我们为git用户指定的git-shell每次一登录就自动退出。

第七步克隆远程仓库

设置git信息

git config --global user.name "你的名字"
git config --global user.email "你的邮箱"

克隆远程仓库:
现在,可以通过git clone命令克隆远程仓库了,在各自的电脑上运行:

git clone git@server:/home/git/test.git

如果服务器的ssh端口不是默认的22的话,比如说6789,可以这样写:

git clone ssh://git@server:6789/home/git/test.git

摘自:

https://www.jianshu.com/p/0c939f63af41

https://www.cnblogs.com/liter7/p/6581344.html

http://blog.51cto.com/11366698/1793600

centos 7 安装git 免密登录

标签:strong   family   改变   本地   mini   https   com   too   microsoft   

原文地址:https://www.cnblogs.com/mrma/p/9952425.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!