惠州公司网站建设,vue网站开发,seo公司重庆,163邮箱企业邮箱注册安装 Git Linux 做为服务器端系统#xff0c;Windows 作为客户端系统#xff0c;分别安装 Git 服务器端#xff1a; #yum install -y git 安装完后#xff0c;查看 Git 版本 [rootlocalhost ~]# git --version
git version 1.7.1 客户端#xff1a; 下载 Git for WindowsWindows 作为客户端系统分别安装 Git 服务器端 #yum install -y git 安装完后查看 Git 版本 [rootlocalhost ~]# git --version
git version 1.7.1 客户端 下载 Git for Windows地址https://git-for-windows.github.io/ 安装完之后可以使用 Git Bash 作为命令行客户端。 安装完之后查看 Git 版本 $ git --version
git version 2.8.4.windows.1 服务器端创建 git 用户用来管理 Git 服务并为 git 用户设置密码 [rootlocalhost home]# id git
id: git无此用户
[rootlocalhost home]# useradd git
[rootlocalhost home]# passwd git 注意密码用字母加数字 服务器端创建 Git 仓库 设置 /home/data/git/gittest.git 为 Git 仓库 然后把 Git 仓库的 owner 修改为 git [rootlocalhost home]# mkdir -p var/www/test/sampla.git
[rootlocalhost home]# git init --bare var/www/test/sample.git
Initialized empty Git repository in /var/www/test/sample.git/
[rootlocalhost home]# cd var/www/test
[rootlocalhost git]# chown -R git:git sample.git/ 客户端 clone 远程仓库 进入 Git Bash 命令行客户端创建项目地址并进入: 从 Linux Git 服务器上 clone 项目输入你的刚设置的密码 当第一次连接到目标 Git 服务器时会得到一个提示 一路 yes 此时 C:\Users\用户名\.ssh 下会多出一个文件 known_hosts以后在这台电脑上再次连接目标 Git 服务器时不会再提示上面的语句。 客户端创建 SSH 公钥和私钥 $ ssh-keygen -t rsa -C 123456789qq.com此时 C:\Users\用户名\.ssh 下会多出两个文件 id_rsa 和 id_rsa.pub id_rsa 是私钥 id_rsa.pub 是公钥 服务器端 Git 打开 RSA 认证 进入 /etc/ssh 目录编辑 sshd_config打开以下三个配置的注释 [rootiZ2zegxsbwybwfq0sv1ragZ test]# cd /etc/ssh
[rootiZ2zegxsbwybwfq0sv1ragZ ssh]# ls
moduli sshd_config ssh_host_dsa_key.pub ssh_host_key.pub ssh_host_rsa_key.pub
ssh_config ssh_host_dsa_key ssh_host_key ssh_host_rsa_key RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys 保存并重启 sshd 服务 [rootlocalhost ssh]# /etc/rc.d/init.d/ssd restart 由 AuthorizedKeysFile 得知公钥的存放路径是 .ssh/authorized_keys实际上是 $Home/.ssh/authorized_keys由于管理 Git 服务的用户是 git所以实际存放公钥的路径是 /home/git/.ssh/authorized_keys 在 /home/git/ 下创建目录 .ssh [rootlocalhost git]# pwd
/home/git[rootlocalhost git]# mkdir .ssh[rootlocalhost git]# ls -a . .. .bash_logout .bash_profile .bashrc .gnome2 .mozilla .ssh 然后把 .ssh 文件夹的 owner 修改为 git [rootiZ2zegxsbwybwfq0sv1ragZgit]# chown -R git:git .ssh [rootiZ2zegxsbwybwfq0sv1ragZ git]# ll -a total 24
drwx------ 3 git git 4096 Aug 8 11:41 .
drwxr-xr-x. 4 root root 4096 Aug 8 11:00 ..
-rw-r--r-- 1 git git 18 Mar 23 08:11 .bash_logout
-rw-r--r-- 1 git git 176 Mar 23 08:11 .bash_profile
-rw-r--r-- 1 git git 124 Mar 23 08:11 .bashrc
drwxr-xr-x 2 git git 4096 Aug 8 11:41 .ssh 将客户端公钥导入服务器端 /home/git/.ssh/authorized_keys 文件 回到windows的 Git Bash 下导入文件 $ ssh git你的远程服务器ip地址 cat .ssh/authorized_keys ~/.ssh/id_rsa.pub 需要输入服务器端 git 用户的密码 回到服务器端查看 .ssh 下是否存在 authorized_keys 文件 注意 修改 .ssh 目录的权限为 700 修改 .ssh/authorized_keys 文件的权限为 600 [rootlocalhost git]# chmod 700 .ssh
[rootlocalhost git]# cd .ssh
[rootlocalhost .ssh]# chmod 600 authorized_keys 客户端再次 clone 远程仓库 $ git clone git47.93.222.78:/var/www/test/sample.git 禁止 git 用户 ssh 登录服务器 之前在服务器端创建的 git 用户不允许 ssh 登录服务器 编辑 /etc/passwd 找到 git:x:502:504::/home/git:/bin/bash 修改为 git:x:502:504::/home/git:/bin/git-shell 此时 git 用户可以正常通过 ssh 使用 git但无法通过 ssh 登录系统。转载于:https://www.cnblogs.com/love-snow/articles/7306178.html