samba配置

http://blog.youkuaiyun.com/yangjuniishz/archive/2008/10/22/3123274.aspx

http://iamcaihuafeng.blog.sohu.com/119687701.html

安装


从samba的官方网站上下载samba的最新版本
wget http://us3.samba.org/samba/ftp/samba-latest.tar.gz
tar zxvf samba-latest.tar.gz
cd samba-3.3.5/source
./configure --with-configdir=/usr/local/samba/etc
make
make install

samba默认安装在目录/usr/local/samba下
[root@CentOS_Test_Server source]# ll /usr/local/samba/
总计 64
drwxr-xr-x  2 root root 4096 06-29 02:29 bin
drwxr-xr-x  2 root root 4096 06-29 02:29 include
drwxr-xr-x 10 root root 4096 06-29 02:29 lib
drwxr-xr-x  2 root root 4096 06-29 02:28 private
drwxr-xr-x  2 root root 4096 06-29 02:29 sbin
drwxr-xr-x  4 root root 4096 06-29 02:28 share
drwxr-xr-x  8 root root 4096 06-29 02:29 swat
drwxr-xr-x  3 root root 4096 06-29 02:28 var

同时在其它的目录下也有与samba有关的文件,如
/etc/samba目录下是samba的配置文件目录
[root@CentOS_Test_Server source]# whereis samba
samba: /etc/samba /usr/lib/samba /usr/local/samba /usr/share/samba

./configure加上--with-configdir表示配置文件保存的目录
[root@CentOS_Test_Server source]# ./configure --help | grep conf
  --with-configdir=DIR    Where to put configuration files ($libdir)

配置
make install操作完成以后,创建etc目录,mkdir /usr/local/samba/etc

samba提供如下4种安全级别
预设 security = share
说明 设定访问 samba server 的安全级别 共有四种
share---不需要提供用户名和密码
user----需要提供用户名和密码,而且身份验证由 samba server 负责
server--需要提供用户名和密码,可指定其他机器(winNT/2000/XP)或另一台 samba server作身份验证
domain--需要提供用户名和密码,指定winNT/2000/XP域服务器作身份验证

编辑samba的配置文件,在最后加入如下的内容,下面是对应security = share时的配置
vi /usr/local/samba/etc/smb.conf
[myshare]
   comment = caihuafeng's share directory #表示注释,可以随便写
   path = /home #要共享给其它服务器的目录
   ;valid users = caihuafeng
   public = yes #是否公开共享
   writable = yes #目录是否可写
   printable = no #是否允许打印
   create mask = 0755 #创建文件时的默认权限

对应security = user时加入的配置为
vi /usr/local/samba/etc/smb.conf
[myshare]
   comment = caihuafeng's share directory #表示注释,可以随便写
   path = /home #要共享给其它服务器的目录
   valid users = caihuafeng
   public = no #
是否公开共享
   writable = yes #目录是否可写
   printable = no #是否允许打印
   create mask = 0755 #创建文件时的默认权限

如果security = user时,则需要增加一个用户到samba中,并设置密码
将操作系统下面的某个用户加入到samba中,提示此用户必须是系统中已经存在的用户,此处的密码可以与系统用户中原来的密码相同,也可以不相同
[root@CentOS_Test_Server samba]# smbpasswd -a caihuafeng
New SMB password:
Retype new SMB password:
Added user caihuafeng.

激活用户
smbpasswd -e caihuafeng

smbpasswd默认操作的是文件/etc/samba/smbpasswd,从下面的操作就可以看出来
[root@CentOS_Test_Server sbin]# more /etc/samba/smbpasswd
caihuafeng:500:685CB0CCB797B5ACAAD3B435B51404EE:4BE3E49709A345BD21E47EB297105F93:[U          ]:LCT-4A4A568B:
[root@CentOS_Test_Server sbin]# smbpasswd -x caihuafeng
Deleted user caihuafeng.
[root@CentOS_Test_Server sbin]# more /etc/samba/smbpasswd

第一次测试:如果密码生成在目录/etc/samba下,则在vista上无法正常访问vista,最后把此文件拷贝到/usr/local/samba/etc下,重新samba的有关服务,然后就可以访问samba了

第二次测试: 给命令smbpasswd加入了-c参数,值为smb.conf的绝对路径,然后生成的密码文件就保存到目录/usr/local/samba/etc下了,这正是我们想要的,生成的密码文件的路径跟着配置文件的路径走
[root@CentOS_Test_Server etc]# smbpasswd -c /usr/local/samba/etc/smb.conf -a caihuafeng
New SMB password:
Retype new SMB password:
startsmbfilepwent_internal: file /usr/local/samba/etc/smbpasswd did not exist. File successfully created.
Added user caihuafeng.
[root@CentOS_Test_Server etc]# smbpasswd -e caihuafeng
Enabled user caihuafeng.
[root@CentOS_Test_Server etc]# cat smbpasswd
caihuafeng:500:685CB0CCB797B5ACAAD3B435B51404EE:4BE3E49709A345BD21E47EB297105F93:[U          ]:LCT-4A4A6363:
[root@CentOS_Test_Server etc]# pwd
/usr/local/samba/etc

如果要删除samba的用户,执行如下的操作
smbpasswd -c /usr/local/samba/etc/smb.conf -x caihuafeng

如果要修改samba用户caihuafeng的密码,执行如下的操作
smbpasswd -c /usr/local/samba/etc/smb.conf -a caihuafeng

然后激活用户
smbpasswd -c /usr/local/samba/etc/smb.conf -e caihuafeng

smbpasswd -a选项的含义
-a
          This option specifies that the username following should be added to the local smbpasswd file, with the
          new  password typed (type <Enter> for the old password). This option is ignored if the username follow-
          ing already exists in the smbpasswd file and it is treated like a regular change password command. Note
          that the default passdb backends require the user to already exist in the system password file (usually
          /etc/passwd), else the request to add the user will fail.

进入samba的sbin目录
[root@CentOS_Test_Server sbin]# cd /usr/local/samba/sbin/
启动samba,最后报错,应该是动态链接库的位置不对,默认在目录/usr/lib下查找动态库,用ln -s建立虚拟连接即可
[root@CentOS_Test_Server sbin]# ./smbd
./smbd: error while loading shared libraries: libtalloc.so.1: cannot open shared object file: No such file or directory

cd /usr/local/samba/lib/
[root@CentOS_Test_Server lib]# ll *.so
lrwxrwxrwx 1 root root 14 06-29 02:29 libnetapi.so -> libnetapi.so.0
lrwxrwxrwx 1 root root 17 06-29 02:29 libsmbclient.so -> libsmbclient.so.0
lrwxrwxrwx 1 root root 21 06-29 02:29 libsmbsharemodes.so -> libsmbsharemodes.so.0
lrwxrwxrwx 1 root root 14 06-29 02:29 libtalloc.so -> libtalloc.so.1
lrwxrwxrwx 1 root root 11 06-29 02:29 libtdb.so -> libtdb.so.1
lrwxrwxrwx 1 root root 16 06-29 02:29 libwbclient.so -> libwbclient.so.0

用ln -s建立链接时最好用绝对路径,可以这样理解,-s后面的第一个参数是原来已经存在的文件或目录,-s后面的第二个参数是要新
生成的链接的名称 ,有时候很容易混淆
ln -s /usr/local/samba/lib/libnetapi.so /usr/lib/libnetapi.so
ln -s /usr/local/samba/lib/libsmbclient.so /usr/lib/libsmbclient.so
ln -s /usr/local/samba/lib/libsmbsharemodes.so /usr/lib/libsmbsharemodes.so
ln -s /usr/local/samba/lib/libtalloc.so /usr/lib/libtalloc.so
ln -s /usr/local/samba/lib/libtdb.so /usr/lib/libtdb.so
ln -s /usr/local/samba/lib/libwbclient.so /usr/lib/libwbclient.so

(解决办法2,我在RH5上这样就可以)
编译方式安装samba出现以下错误:
error while loading shared libraries: libtalloc.so. 1: cannot open shared object file: No such file or directory
解决办法:  vi /etc/ld.so.conf
加入:  /opt/samba/lib
执行  ldconfig 同时要启动下面的两个服务
./smbd
./nmbd

如果更改了配置文件/usr/local/samba/etc/smb.conf或进行了其它的操作需要重启服务时,执行操作
killall smbd
killall nmbd
然后再重新启动这两个服务
./smbd
./nmbd

判断服务是否已经启动
[root@CentOS_Test_Server sbin]# pstree | grep smbd
     |-smbd---smbd
[root@CentOS_Test_Server sbin]# pstree | grep nmbd
     |-nmbd

测试


最后在vista下访问所共享的目录
方式一
开始 -> 运行,键入//192.168.1.111/myshare( mysahre对应配置文件/usr/local/samba/etc/smb.conf中的[mysahre],实际上是访问的是CentOS下面的/home目录下面的内容 )即可,192.168.1.111是安装samba的服务器的ip地址

方式二
打开资源管理器,点击工具 -> 映射网络驱动器,在文件夹里面输入//192.168.1.111/share即可

如果要提示输入用户名及密码,则输入上述设定好的用户名及密码,然后即可像操作windows的本地文件或目录一样操作服务器上的文件或目录,有时会比SSH,SCP,SVN等那些工具显得更加方便

如果访问上述mysahre文件夹对应的用户或密码已经更改,则在客户端(如在vista下)必须首先 断开网络驱动器, 然后再重新 映射网络驱动器 ,否则会报错,这点千万要注意啊。



编辑启动脚本
vi /usr/local/samba/sbin/start.sh,键入如下的内容
#!/bin/sh

/usr/bin/killall smbd nmbd
sleep 1
/usr/local/samba/sbin/smbd
/usr/local/samba/sbin/nmbd

vi /etc/rc.local,在最后面加入如下的一行即可
/usr/local/samba/sbin/start.sh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值