重启linux pam服务,Centos 6.5上Apache + PAM + SVN服务安装配置(使用本地系统用户认证)...

类别:原创 服务器

本文参考

http://blog.csdn.net/sxhong/article/details/9176881

svn 操作命令 参考 http://blog.csdn.net/gexiaobaohelloworld/article/details/7752862

第一:说明,软件说明,和安装的目的

架设基于linux下的SVN服务器,进行版本控制,并使用本地系统用户名和密码进行登陆认证。

第二:本例操作环境

所使用的系统环境为 Centos 6.5 64位操作系统

[root@tian ~]# uname -a

Linux tian.test.com 2.6.32-431.11.2.el6.x86_64 #1 SMP Tue Mar 25 19:59:55 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

[root@tian ~]# hostname

tian.test.com

[root@tian ~]# more /etc/redhat-release

CentOS release 6.5 (Final)

[root@tian ~]#

第三:服务器安装和基本配置

1.  安装必须的软件包

mod_dav_svn

subversion

httpd

[root@tian ~]# yum install mod_dav_svn subversion httpd -y

[root@tian ~]# httpd -v

Server version: Apache/2.2.15 (Unix)

Server built:   Apr  3 2014 23:56:16

[root@tian ~]#

[root@tian ~]# svnserve --version

svnserve, version 1.6.11 (r934486)

compiled Mar  6 2014, 10:49:10

后面省略

[root@tian ~]#

2.创建svn仓库

有了SVN软件后还需要建立SVN库,建立两个示例库test1 test2

[root@tian ~]# mkdir /svndata

[root@tian ~]# svnadmin  create /svndata/test1/

执行上面的命令后,自动建立多个文件, 分别是conf, db, format, hooks, locks, README.txt

[root@tian ~]# ls /svndata/test1/

conf  db  format  hooks  locks  README.txt

[root@tian ~]# svnadmin  create /svndata/test2

[root@tian ~]#

[root@tian ~]# cat /etc/httpd/conf/httpd.conf | grep apache | grep -v "#"

User apache

Group apache

[root@tian ~]#

[root@tian ~]# grep apache /etc/passwd

apache:x:48:48:Apache:/var/www:/sbin/nologin

[root@tian ~]#

[root@tian ~]# chown apache -R /svndata

[root@tian ~]# chmod -R 700  /svndata

[root@tian ~]# ll /svndata/

total 8

drwx------ 6 apache root 4096 Apr 16 10:14 test1

drwx------ 6 apache root 4096 Apr 16 10:32 test2

3.配置apache

[root@tian ~]# vi /etc/httpd/conf/httpd.conf

\\修改ServerName,否则启动apache会报错 修改后如下

[root@tian ~]# cat /etc/httpd/conf/httpd.conf | egrep ServerName |egrep -v "^#|^$"

ServerName localhost

4.查看svn的apache模块

[root@tian ~]# ll /etc/httpd/modules/mod_* | grep svn

-rwxr-xr-x 1 root root  13456 Mar  6 18:52 /etc/httpd/modules/mod_authz_svn.so

-rwxr-xr-x 1 root root 153472 Mar  6 18:52 /etc/httpd/modules/mod_dav_svn.so

[root@tian ~]#

5.简单配置svn

[root@tian ~]# vim /etc/httpd/conf.d/subversion.conf

[root@tian ~]# cat /etc/httpd/conf.d/subversion.conf |egrep -v "^#|^$"

subversion.conf的详细内容(去掉注释后):

LoadModule dav_svn_module     modules/mod_dav_svn.so

LoadModule authz_svn_module   modules/mod_authz_svn.so

DAV svn

SVNPath /svndata/test1

DAV svn

SVNPath /svndata/test2

[root@tian ~]#

6.启动httpd服务

[root@tian ~]# service httpd restart

Stopping httpd:                                            [FAILED]

Starting httpd:                                            [  OK  ]

[root@tian ~]#

7.开机启动httpd服务

[root@tian ~]# chkconfig httpd on

这个配置的内容是最基本,没有指定认证方式,所以是可以匿名访问的,在访问时使用的路径是:http://host/svn/test1  及 http://host/svn/test2

第四:进阶配置(使用http方式认证)

1.设置密码文件

[root@tian ~]# htpasswd -cm /etc/svn-passwd-file-test1  tian

New password:

Re-type new password:

Adding password for user tian

[root@tian ~]# more /etc/svn-passwd-file-test1

tian:$apr1$Np79jiyx$TAATTmBzK5DM8zP2hJJsm/

[root@tian ~]#

2.设置权限文件

[root@tian ~]# cat >> /etc/svn-authz-file-test1 <

[/]

tian=rw

EOF

[root@tian ~]# more /etc/svn-authz-file-test1

[/]

tian=rw

[root@tian ~]#

[root@tian ~]# cp /etc/svn-passwd-file-test1 /etc/svn-passwd-file-test2

[root@tian ~]# cp /etc/svn-authz-file-test1 /etc/svn-authz-file-test2

[root@tian ~]#

3.修改配置文件

[root@tian ~]# vim /etc/httpd/conf.d/subversion.conf

subversion.conf的详细内容:

[root@tian ~]# cat /etc/httpd/conf.d/subversion.conf |egrep -v "^#|^$"

LoadModule dav_svn_module     modules/mod_dav_svn.so

LoadModule authz_svn_module   modules/mod_authz_svn.so

DAV svn

SVNPath /svndata/test1

AuthType Basic

AuthName "Authorization Realm"

AuthzSVNAccessFile /etc/svn-authz-file-test1          \\ 权限认证文件

AuthUserFile /etc/svn-passwd-file-test1               \\ 密码文件

Require valid-user

DAV svn

SVNPath /svndata/test2

AuthType Basic

AuthName "Authorization Realm"

AuthzSVNAccessFile /etc/svn-authz-file-test2           \\ 权限认证文件

AuthUserFile /etc/svn-passwd-file-test2                \\ 密码文件

Require valid-user

[root@tian ~]#

4.重启服务

[root@tian ~]# service  httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

[root@tian ~]#

这个配置的内容是中指定了认证方式,在访问时使用的路径是:http://host/svn/test1 或 http://host/svn/test2

输入用户名和密码可以登录表示成功!

5.测试

[root@tian ~]# svn co --username tian --password 123456 http://127.0.0.1/svn/test1 svn/test1

Checked out revision 0.

[root@tian ~]# ls svn/test1/

[root@tian ~]# touch  svn/test1/aa

[root@tian ~]# touch  svn/test1/bb

[root@tian ~]# svn add svn/test1/aa svn/test1/bb

A         svn/test1/aa

A         svn/test1/bb

[root@tian ~]# svn ci -m "test"  svn/test1/aa svn/test1/bb

Adding         svn/test1/aa

Adding         svn/test1/bb

Transmitting file data ..

Committed revision 1.

[root@tian ~]#

[root@tian ~]# ls svn/test1/

aa  bb

[root@tian ~]# svn update svn/test1/

At revision 1.

[root@tian ~]#

第五:进阶配置(使用pam认证,使用本地系统用户)

1.安装pam模块

[root@tian ~]# ls /etc/httpd/modules/mod_auth_pam.so

ls: cannot access /etc/httpd/modules/mod_auth_pam.so : No such file or directory

[root@tian ~]# ls /etc/httpd/modules/mod_auth_sys_group.so

ls: cannot access /etc/httpd/modules/mod_auth_sys_group.so: No such file or directory

[root@tian ~]#

[root@tian ~]# rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm          \\ 安装epel的yum源,此源中提供 mod_auth_pam模块

[root@tian ~]#

[root@tian ~]# yum install -y mod_auth_pam

[root@tian ~]#

[root@tian ~]# ls /etc/httpd/modules/mod_auth_pam.so

/etc/httpd/modules/mod_auth_pam.so

[root@tian ~]# ls /etc/httpd/modules/mod_auth_sys_group.so

/etc/httpd/modules/mod_auth_sys_group.so

[root@tian ~]#

2.检查默认的pam配置

[root@tian ~]# more /etc/httpd/conf.d/auth_pam.conf

LoadModule auth_pam_module modules/mod_auth_pam.so

LoadModule auth_sys_group_module modules/mod_auth_sys_group.so

[root@tian ~]# more /etc/pam.d/httpd

#%PAM-1.0

auth       include      password-auth

account    include      password-auth

# Comment out the previous account line and uncomment the following line if

# you wish to allow logins that don't have a system account

#account    required     pam_permit.so

[root@tian ~]#

3.新建测试用户和svn用户组,并进行相关配置

新建可以访问svn的用户组,这里是svn (gid 504),并只有svn组里的用户才能访问svn资源,注意一定要将运行httpd的用户加入到此组中,否则,httpd程序无法读取 /etc/shadow 文件,造成svn不能成功认证

[root@tian ~]# groupadd svn

[root@tian ~]# grep svn /etc/group

svn:x:504:

[root@tian ~]# useradd test

[root@tian ~]# passwd test

Changing password for user test.

New password:

BAD PASSWORD: it is based on a dictionary word

Retype new password:

passwd: all authentication tokens updated successfully.

[root@tian ~]#

[root@tian ~]# usermod -a -G svn test

[root@tian ~]# cat /etc/httpd/conf/httpd.conf | grep apache | grep -v "#"

User apache

Group apache

[root@tian ~]#

[root@tian ~]# usermod -a -G svn apache

[root@tian ~]# grep svn /etc/group

svn:x:504:test,apache

[root@tian ~]# chgrp svn /etc/shadow

[root@tian ~]# ll /etc/shadow

-r--r----- 1 root svn 938 Apr 16 11:57 /etc/shadow

[root@tian ~]#

4.设置权限文件

[root@tian ~]# cat >> /etc/svn-authz-file-test1 <

[/]

test=rw

EOF

[root@tian ~]#  more /etc/svn-authz-file-test1

[/]

tian=rw

[/]

test=rw

[root@tian ~]#

5.修改配置文件,使用本地系统用户

说明:此处我们对两个svn资源分别使用两种验证方式:

test1,使用本地系统用户验证(用户必须属于svn用户组)

test2,使用svn的密码文件进行验证,用户不是本地系统用户

[root@tian ~]# cat /etc/httpd/conf.d/subversion.conf |egrep -v "^#|^$"

LoadModule dav_svn_module     modules/mod_dav_svn.so

LoadModule authz_svn_module   modules/mod_authz_svn.so

DAV svn

SVNPath /svndata/test1

AuthType Basic

AuthName "Authorization Realm"

AuthUserFile /etc/svn-passwd-file-test1                       \\仍使用 svn-passwd-file-test1 文件控制访问权限

Require group svn                                             \\只有属于本地用户组svn中的用户才能访问

DAV svn

SVNPath /svndata/test2

AuthType Basic

AuthName "Authorization Realm"

AuthzSVNAccessFile /etc/svn-authz-file-test2

AuthUserFile /etc/svn-passwd-file-test2      \\ 使用此处指定文件中的用户名和密码进行验证

Require valid-user

[root@tian ~]#

6.重启服务

[root@tian ~]# service  httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

[root@tian ~]#

7.测试

test1 使用本地系统用户组svn中的用户进行验证

test2 使用密码文件进行认证

[root@tian ~]# svn co --username test --password test123 http://127.0.0.1/svn/test1 svn/test1

Checked out revision 1.

[root@tian ~]# svn update svn/test1/

At revision 1.

[root@tian ~]# svn co --username tian --password 123456 http://127.0.0.1/svn/test2 svn/test2

Checked out revision 0.

[root@tian ~]# svn update svn/test2

At revision 0.

[root@tian ~]#

[root@tian ~]# ls svn/test1

aa  bb

[root@tian ~]# ls svn/test2

[root@tian ~]#

第六:补充 更多信息

1. 在上面的配置中通过SVNPath指定了一个代码仓库。但是在实际应用,往往是有多个仓库存放不同的项目代码,这时可以将SVNPath改为:

SVNParentPath  /svndata

但此时的不足是,因各仓库的权限控制使用的是一个权限控制文件,所以各仓库的权限保持的完全一致

2.当有多个项目时 ,其实是建议设置多个目录,分别进行权限控制,如下

DAV svn

SVNPath /svndata/test1/

AuthType Basic

AuthName "Authorization Realm"

AuthzSVNAccessFile /etc/svn-authz-file-test1

AuthUserFile /etc/svn-passwd-file-test1

Require valid-user

DAV svn

SVNPath /svndata/test2/

AuthType Basic

AuthName "Authorization Realm"

AuthzSVNAccessFile /etc/svn-authz-file-test2

AuthUserFile /etc/svn-passwd-file-test2

Require valid-user

3. 使用htpasswd添加用户时,认证文件svn-auth-file不存在时,使用:

htpasswd -cm /etc/svn-auth-file-test2 tester01

会创建一个的文件,并且添加tester01用户。而此后再增加用户,使用:

htpasswd /etc/svn-auth-filetest2 tester02

4. 新增加代码库后,一定修改文件夹权限,否者客户端会得到Permission Denied的提示。

5. 每次修改过配置文件以后,都要重新启动httpd服务。

6. svn中指定用户使用访问的方法

Require group svn           \\ 只有属于本地用户组svn中的用户才能访问

Require user test           \\ 只有test用户才能访问

7. 必须注意,如果使用本地系统用户进行验证,一定要确保运行httpd的用户能读取/etc/shadow中的内容

8. 无论使用那种认证方式,权限控制都可以使用 AuthzSVNAccessFile 参数指定的文件来进行控制

至此 所有配置完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值