分别在服务器和本地安装最新版本的git
==通常centos上使用yum源安装的git版本过低==
// 查看当前git版本
# git --version
git version 1.7.1
// 卸载旧版本
# yum remove -y git
# yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
# wget https://github.com/git/git/archive/v2.13.2.tar.gz
# tar zxf v2.13.2.tar.gz
# cd git-2.13.2
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install
# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
# source /etc/bashrc // 实时生效
# git --version
git version 2.13.2
libgit.a(utf8.o): In function `reencode_string_iconv':
/usr/local/src/git-2.13.2/utf8.c:463: undefined reference to `libiconv'
libgit.a(utf8.o): In function `reencode_string_len':
/usr/local/src/git-2.13.2/utf8.c:524: undefined reference to `libiconv_open'
/usr/local/src/git-2.13.2/utf8.c:535: undefined reference to `libiconv_close'
/usr/local/src/git-2.13.2/utf8.c:529: undefined reference to `libiconv_open'
collect2: ld returned 1 exit status
make: *** [git-credential-store] Error 1
可以按照如下方式解决
// 对之前git的make 操作进行 make clean
# make clean
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
# tar zxf libiconv-1.14.tar.gz
# cd libiconv-1.14
# ./configure --prefix=/usr/local/libiconv
# make && make install
// 创建一个软链接到/usr/lib
# ln -s /usr/local/lib/libiconv.so /usr/lib
# ln -s /usr/local/lib/libiconv.so.2 /usr/lib
然后
# make configure
# ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv/
# make && make install
# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
# source /etc/bashrc
# git config --global user.name 'your name'
# git config --global user.email 'your email address'
# useradd git
// 为安全起见,禁用 git 用户的 shell 登录
# vim /etc/passwd
// 修改 git 用户的 shell 为 git-shell,路径使用 which git-shell 查看
// 找到如下一行
git:x:1001:1001::/home/git:/bin/bash
// 修改成如下
git:x:1001:1001::/home/git:/usr/local/git/bin/git-shell
// 进入到项目目录
# git init
// 创建一个裸仓库
# git clone --bare ProjectPath /srv/myProject.git
// 进入到项目目录
# git remote add origin /srv/myProject.git
// 修改远程仓库所属主和所属组
# chown -R git.git /srv/myProject.git
# git add .
# git commit -m 'comment'
# git push origin master
# su git
$ cd ~
$ make .ssh
$ chmod 700 .ssh
$ cd .ssh
$ touch authorized_keys
$ chmod 600 authorized_keys
// 然后在 authorized_keys 文件中加入本地用户的公钥 id_rsa.pub
# vim /etc/ssh/sshd_config
// 找到下面3行并去掉注释
1. RSAAuthentication yes
2. PubkeyAuthentication yes
3. AuthorizedKeysFile .ssh/authorized_keys
// 打开 git-bash,生成公钥
$ ssh-keygen -t rsa
// 在用户目录下的.ssh目录里面会生成 id_rsa, id_rsa.pub
// 将 id_rsa.pub 里的内容拷贝到服务器上
==类似使用搬瓦工VPS的可能默认ssh端口不是22的需要配置这个==
Host your domain name or server ip
User 服务端添加的git用户名
Hostname your domain name or server ip
Port ssh 端口
IdentityFile ~/.ssh/id_rsa
$ git clone yrscgit@yrsc0597.com:/srv/yrsc.git
转载请注明出处