samba服务器配置及常见异常解决(fedora)

samba服务器配置及常见错误解决(fedora)

Samba服务器配置及错误解决

1)首先检查系统是否安装好了samba

[root@localhost mnt]# rpm -qa | grep samba

如果出现下面三行内容,则表示已经安装好了Samba

samba-winbind-clients-3.4.2-47.fc12.i686

samba-common-3.4.2-47.fc12.i686

samba-3.4.2-47.fc12.i686

如果没有安装好,需要挂载安装光盘Fedora-12-i386-DVD.iso

[root@localhost /]# mount  –tauto  /dev/cdrom /mnt/

若出现mount: block device /dev/sr0 is write-protected, mountingread-only,则表明挂载成功,挂载成功后会在挂载目录(这里是/mnt/出现Packages等文件夹),进入到Packages目录下。

 [root@localhost Packages]# rpm -ivh samba-3.4.2-47.fc12.i686.rpm

即可安装成功。

如果不能安装,有依赖关系提示的话,请使用yum安装:

[root@localhostPackages]# yum localinstall samba-3.4.2-47.fc12.i686.rpm

2 配置smb

[root@localhost /]# cd/etc/samba/

[root@localhost samba]#ls

lmhosts  smb.conf  smbpasswd  smbusers

这里的smb.confsamba服务器的主要配置文件。

还要注意一点,smbpasswd文件是用来存储用户帐号和经过md5加密后的密码。

刚安装好samba服务时,此文件不存在。需要手工创建。下面会介绍。

编辑smb.conf文件

workgroup = WORKGROUP

server string = %U's samba %v

netbios name = fedora

log file = /var/log/samba/log.%m

max log size = 50

security = user

[root]

comment = root

path = /

public = no

writable = yes

write list = wangwei

 

path表示共享的目录,这里是根目录,由于是虚拟机上面的所以我不会在意。可以修改为其他目录。

 

3)添加smb共享目录的用户

1)建一个系统用户

[root@localhostsamba]#  useradd testuser (建一个名叫testuser的用户)

[root@localhostsamba]#  passwd testuser (给testuser用户添加密码)

Changing password foruser samba.

New password: (密码要六位以上,不显示在屏幕上)

BAD PASSWORD: it does notcontain enough DIFFERENT characters

Retype newpassword: (确认密码)

passwd: allauthentication tokens updated successfully

2) 更新 /etv/samba/smbpasswd 文件

[root@localhost samba]# cat /etc/passwd | mksmbpasswd.sh >/etc/samba/smbpasswd

3) 然后创建samba帐户

[root@localhost samba]# smbpasswd -a testuser

New SMB password:

Retype new SMB password:

Added user testuser.

4)关闭不必要的服务

有的时候不能远程到linux或者windows下不能直接创建该linuxsamba的网络驱动器就是因为下面的这两个问题。

1  打开selinux共享

[root@localhost samba]# setsebool -P samba_enable_home_dirs on

2  开启samba读写权限

[root@localhost samba]# setsebool -P samba_export_all_rw on

3  关闭防火墙

[root@localhost samba]#chkconfig iptables off (永久关闭,重启不复原)

[root@localhost samba]#service iptables stop (马上生效,启动后又打开了)

5 启动smb服务

[root@localhost samba]# service smb restart

 [root@localhost samba]# service nmb restart

 [root@sample ~]# chkconfig smb on  ← 设置Fedora Samba 自启动
[root@sample ~]# chkconfig --list smb  ← 确认Fedora Samba 启动标签,确认 2-5 为 on 的状态
smb 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@sample ~]# chkconfig nmb on  ← 设置 nmb 自启动
[root@sample ~]# chkconfig --list nmb  ← 确认 nmb 启动标签,确认 2-5 为 on 的状态
nmb 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@sample ~]# /etc/rc.d/init.d/smb start  ← 启动 Fedora Samba 服务
Starting SMB services: [ OK ]
[root@sample ~]# /etc/rc.d/init.d/nmb start  ← 启动 nmb 服务
Starting NMB services: [ OK ]

Ps:请确认是否安装ssh。 安装: yuminstall ssh

 

配置samba服务器常见错误及解决办法:

配置samba服务器的错误记录(整理自网络):

windowslinux相互能ping通,但sshsecureCR无法连接!

1、看看sshd服务是否启动,启动是否正常
2
service sshd status
看看有没有返回值
3
、查看日志
tail -200 /var/log/secure
4
、关闭防火墙
service iptables stop
5
、关闭selinux
vi /etc/selinux/config
selinux=disabled
(需要重启)
6
service sshd restart
telnet XXX.XXX.XXX.XXX 22

7、上面的问题都无法解决,而且别人还可以通过ssh登陆到你的虚拟机。就是自己不可以。

最后杀手锏了:在VMWare中安装好linux系统后,选择桥接,从宿主机Windows上使用Putty, SSH Secure Shell等客户端工具连接linux上的ssh服务,客户端一直没有反应,无法输入密码进行登陆。宿主机和虚拟机之间互相ping没有问题。linux防火墙和windows防火墙都已经禁用。IP设置在同一网段,SSH服务正常运行在22端口,配置也没有问题(不然客户端连接不进来)。FTP等也是一样,无法从宿主机连接到linux上的服务。一切设置一切该设置的似乎都正常,而且同样的步骤在其他机器上就可以达到自己的目的了。但是这个时候你的机器就是不行。而且办公室其他同事的机器就是还可以通过ssh登陆到你的linux上,就是你自己不行。不过总会有高手解决这个问题的。

首先要感谢ningzuowu,我是按照他提供的方法解决的。地址为:http://bbs.chinaunix.net/archiver/tid-943452-page-2.html


说直接一点就是将网卡的 高级 选项卡中 ----  属性 ---- 硬件校验和 设置为关闭。(需要重启)

以下是截图说明:

 1. 本地连接,选择属性,选择配置

2. 在高级选项卡中,选择硬件校验和,将其值设为关闭,等待网络自动重新启动后,便可以使用SSH工具成功连接VMWare中的linux了。

 

原因猜想:

桥接模式下,虚拟机和宿主机共用一个网卡,在同一网卡上传输数据包,可能会有问题,但为何需要关闭硬件校验和,尚需高人指点。

可能影响:

关闭硬件校验和,是否会造成网络不稳定,或其它问题,还没有测过,如果有发现问题或者有更好的方法望指出。