歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Linux(CentOS 6)安裝SVN支持svn和svn+ssh方式

svn方式很簡單,svnadmin create之後svnserve啟動就可以訪問,用svn+ssh方式需要使用serve的tunel即隧道方式,即在登錄時啟動一個隧道將請求作為svn方式。

這個方式好像很難找到資料,百度上的真是大多是互相copy,幾乎都不驗證,費了老半天勁才搞明白如何做。

其中有幾點要注意:

1. svn+ssh,需要添加一個linux系統用戶,能登錄系統的。

2. 用ssh-keygen生成密鑰後,需要改為authorized_keys,並且指定command為svnserve的隧道。

3.在checkout時和svn方式不一樣,“svn co svn://192.168.11.222/repos”,而後者是“svn co svn+ssh://[email protected]/svnroot/repos”,一定要加上路徑,否則會說找不到這個repository.

4.新建一個svn用戶,在auth裡指定權限,在passwd裡指定密碼,用svn方式就可以訪問;同時它可以作為ssh方式的隧道。

5. 新建一個系統用戶,在.ssh/authorized_keys指定隧道。

6.需要將svn用戶和系統用戶都添加到auth裡面,否則會說Authorized failed。

以下是詳細步驟:

除了“ssh-keygen -t rsa -b 1024”生成密鑰那裡需要敲幾個回車,其他地方都可以直接執行。

echo "for CentOS5.5 x86_64bit"
echo "refer to: http://wiki.centos.org/HowTos/Subversion"

##################################################################################
##################################################################################
# install apache-svn module.
sudo yum install -y subversion
# 安裝subversion時會安裝svn服務器端

# start svnserver, specifies the svnroot.
sudo mkdir /svnroot
sudo chmod 777 /svnroot

# create repos
cd /svnroot/
svnadmin create repos

# disable anon
cd /svnroot/repos/conf
cat << END > svnserve.conf
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
[sasl]
# use-sasl = true
# min-encryption = 0
# max-encryption = 256
END

# add auth
cd /svnroot/repos/conf
# add to the end of file.
cat << END > authz
[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average

[groups]
# harry_and_sally = harry,sally
# [repository:/baz/fuz]
# @harry_and_sally = rw

[/]
# svnuser is not a system user, just a user in svn, whose password stored in ./passwd.
svnuser=rw
END

# add user to svn
cd /svnroot/repos/conf
cat << END > passwd
[users]
svnuser=svnuser_password
END

# start server
svnserve -d -r /svnroot

# client checkout
cd;
rm -rf repos
svn co svn://192.168.11.222/repos

# support svn+ssh.
##################################################################################
##################################################################################
# add user linuxuser
sudo useradd linuxuser
# set password to linuxuser_password
printf "linuxuser_password\nlinuxuser_password"|sudo passwd linuxuser

# generate public/private key.
sudo su linuxuser
# press enter 3times.
cd;
mkdir .ssh
cd .ssh
ssh-keygen -t rsa -b 1024
# generate tunnel
rm -f authorized_keys
# you may need to modify the svnroot and svnuser if need.
echo -n 'command="/usr/bin/svnserve -t -r /svnroot --tunnel-user=svnuser"' >> authorized_keys
echo -n ',no-port-forwarding,no-pty,no-agent-forwarding,no-X11-forwarding' >> authorized_keys
echo -n ' ' >> authorized_keys
cat id_rsa.pub >> authorized_keys
exit

# we must add the svnuser and linuxuser to the svn auth
cd /svnroot/repos/conf
cat << END > authz
[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average

[groups]
# harry_and_sally = harry,sally
# [repository:/baz/fuz]
# @harry_and_sally = rw

[/]
# svnuser is not a system user, just a user in svn, whose password stored in ./passwd.
svnuser=rw
# we must add the linux user also.
linuxuser=rw
END

# chechout
cd;
rm -rf repos
svn co svn+ssh://[email protected]/svnroot/repos

Copyright © Linux教程網 All Rights Reserved