Linux下搭建SVN服务器

环境

Ubuntu 24.10 Server

安装

1
sudo apt install subversion

测试svn

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ svnserve --version
svnserve, version 1.14.3 (r1914484)
compiled Aug 16 2024, 12:46:27 on x86_64-pc-linux-gnu

Copyright (C) 2023 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/

The following repository back-end (FS) modules are available:

* fs_fs : Module for working with a plain file (FSFS) repository.
* fs_x : Module for working with an experimental (FSX) repository.
* fs_base : Module for working with a Berkeley DB repository.

Cyrus SASL authentication is available.

创建版本库目录

1
2
cd #切换到HOME目录
sudo mkdir /var/svn

创建版本库

1
sudo svnadmin create /var/svn/name

进入name目录

1
2
3
4
5
6
7
8
9
10
cd /var/svn/name

$ ll
total 24
drwxr-xr-x 2 root root 4096 Mar 29 20:14 conf
drwxr-sr-x 6 root root 4096 Mar 29 20:14 db
-r--r--r-- 1 root root 2 Mar 29 20:14 format
drwxr-xr-x 2 root root 4096 Mar 29 20:14 hooks
drwxr-xr-x 2 root root 4096 Mar 29 20:14 locks
-rw-r--r-- 1 root root 246 Mar 29 20:14 README.txt

修改配置

进入配置文件

1
2
3
4
5
6
7
8
cd conf

$ ll
total 20
-rw-r--r-- 1 root root 1080 Mar 29 20:14 authz
-rw-r--r-- 1 root root 885 Mar 29 20:14 hooks-env.tmpl
-rw-r--r-- 1 root root 309 Mar 29 20:14 passwd
-rw-r--r-- 1 root root 4375 Mar 29 20:14 svnserve.conf
  • authz:负责账号权限的管理,控制账号是否读写权限
  • passwd:负责账号和密码的用户名单管理
  • svnserve.conf:svn服务器配置文件

authz

在authz文件底部添加

1
2
[/] # 表示根目录,即 /var/svn/repos
jackey = rw # 表示用户jackey对根目录具有读写权限

passwd

添加

1
jackey = passwd # 用户名为:jackey,认证密码为:passwd

svnserve.conf

1
2
3
4
5
6
anon-access = none #表示禁止匿名用户访问。
auth-access = write #表示授权用户拥有读写权限。
password-db = passswd #指定用户名口令文件,即 passwd 文件。
authz-db = authz #指定权限配置文件,即 authz 文件。
realm = /var/svn/repos #指定认证域,即 /var/svn/repos 目录。
#注意:所有以上的配置项都需要顶格,即前面不能预留空格,否则报错

服务

启动SVN服务

1
sudo svnserve -d -r /var/svn

查看是否成功

1
2
3
$ ps -ef | grep 'svnserve'
root 22772 1 0 20:25 ? 00:00:00 svnserve -d -r /var/svn
ubuntu 22809 21029 0 20:25 pts/0 00:00:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox svnserve

访问

需要打开系统端口

自测试

1
svn co svn://ip:3690/name

会要求输入密码。

客户端访问

tortoisesvn下载软件包,默认流程安装。

进入某个文件夹,右键菜单选择checkout拉取库

菜单

输入地址

检出

此时会弹出授权界面,输入用户名和密码。

检出

推送

向空目录添加一个文件,点击鼠标右键

菜单

显示提交界面

菜单

选择需要添加的文件

菜单

点击Ok按钮提交至服务器

菜单

ssh

密码为明文不太安全,考虑使用SSH授权。

先设置ssh客户端目录,putty/git都可以。

菜单

命令变成为

1
svn checkout svn+ssh://user@ip/full/path

Linux下搭建SVN服务器
https://blog.jackeylea.com/linux/how-to-setup-svn/
作者
JackeyLea
发布于
2025年3月31日
许可协议