利用samba建立ubuntu与windows间点到点互连

        实验室的电脑安装的是Windows XP系统,我自己的笔记本安装的是ubuntu,之前苦于常常想操作电脑A的时候,却按了电脑B的键盘,让我浑身不自在,于是google网上的解决方法,发现了synergy这个好东西,通过共享设备的方式,两电脑共用同一套鼠标键盘,操作问题得到了解决!

        然而,synergy两台电脑不能互相拷贝文件,作为一个弱弱的码农,目前还没有能力在synergy这个开源项目上扩展文件共享的功能,然而,笨人有笨人的方法,我决定给笔记本上个samba服务器,把自己的文件全部扔在服务器的共享目录下,windows端通过连接这个服务器,就可以同步修改这些文件,同时也就实现了文件共享,非常方便。


        参考文章1,具体步骤如下:

前提条件:

       你的Linux机器最好是有一个静态IP,当然是DHCP的话,也可以用,不过就不能使能“WINS”选项功能(后面会提到)。

(1)linux端:

        先安装samba服务器

       sudo apt-get install samba

        然后确保samba当前是停止的

       sudo /etc/init.d/samba stop

        备份旧的配置

       sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.template

        创建新的配置

      sudo touch /etc/samba/smb.conf
       编辑此文件
      sudo gedit /etc/samba/smb.conf

[global]
    ; General server settings
    netbios name = YOUR_HOSTNAME
    server string =
    workgroup = YOUR_WORKGROUP
    ; announce version = 5.0
    socket options = TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192

    passdb backend = tdbsam
    security = user
    null passwords = true
    username map = /etc/samba/smbusers
    name resolve order = hosts wins bcast

    wins support = yes

    printing = CUPS
    printcap name = CUPS

    syslog = 1
    syslog only = yes

; NOTE: If you need access to the user home directories uncomment the
; lines below and adjust the settings to your hearts content.
;[homes]
    ;valid users = %S
    ;create mode = 0600
    ;directory mode = 0755
    ;browseable = no
    ;read only = no
    ;veto files = /*.{*}/.*/mail/bin/

; NOTE: Only needed if you run samba as a primary domain controller.
; Not needed as this config doesn't cover that matter.
;[netlogon]
    ;path = /var/lib/samba/netlogon
    ;admin users = Administrator
    ;valid users = %U
    ;read only = no

; NOTE: Again - only needed if you're running a primary domain controller.
;[Profiles]
    ;path = /var/lib/samba/profiles
    ;valid users = %U
    ;create mode = 0600
    ;directory mode = 0700
    ;writeable = yes
    ;browseable = no

; NOTE: Inside this place you may build a printer driver repository for
; Windows - I'll cover this topic in another HOWTO.
[print$]
    path = /var/lib/samba/printers
    browseable = yes
    guest ok = yes
    read only = yes
    write list = root
    create mask = 0664
    directory mask = 0775

[printers]
    path = /tmp
    printable = yes
    guest ok = yes
    browseable = no

; Uncomment if you need to share your CD-/DVD-ROM Drive
;[DVD-ROM Drive]
    ;path = /media/cdrom
    ;browseable = yes
    ;read only = yes
    ;guest ok = yes

[MyFiles]
    path = /media/samba/
    browseable = yes
    read only = no
    writeable = yes
    guest ok = no
    create mask = 0770
    directory mask = 0770
    ; force user = YOUR_USERNAME
    force group = YOUR_USERGROUP

       其中,有几个地方要改:
-> netbios name = YOUR_HOSTNAME
      用你自定义的主机名替换
"YOUR_HOSTNAME",中间不能有空格。 
      比如:
      netbios name = LUOCANWEI_SERVER
-> workgroup = YOUR_WORKGROUP
      用windows的工作组名称替换"YOUR_WORKGROUP" ,要确保跟连接的windows所在的工作组是一致的。
      比如:
      workgroup = WORKGROUP

-> wins support = yes
     如果你的Linux机器有一个静态IP地址,或者你不能配置你的路由/服务器提供一个固定的租用DHCP地址,这个配置选项配置为"no"。这样的话,你就不能使用到WINS的优势了。

-> [MyFiles]
     这个是windows所看到的共享目录的名字,不更改也行,或者改为你自己想要的也行。不要超过31个字符,不要使用空格。

-> path = /media/samba/
     共享文件存储的真实目录。如果linux上没有这个目录,就新建一个!
     建议创建在另外一个有足够大存储空间的分区,如/home 
    sudo mkdir /home/samba
     比如:
     path = /home/samba/

-> browseable = yes
    windows端可以看到这个文件夹

-> writeable = yes
    可以写

    其他选项,如create mask, directory mask,force user,force group就参看链接2。
    这样,我们就修改完smb.conf了,保存之~~ 启动吧,骚年~步骤是:

    sudo /etc/init.d/samba start
    若有错误,检查配置文件有没有不对的地方,如路径是不是不存在;

    接着添加用户

    sudo smbpasswd -L -a your_username
    sudo smbpasswd -L -e your_username
    比如:
    sudo useradd -s /bin/true ray ;linux创建新用户
    sudo smbpasswd -L -a ray  ;之后要求你输入和确认smb的登陆密码
    sudo smbpasswd -L -e ray  ;使能
    其中"-s /bin/true" , -s就是shell, true命令啥都不做,只设置退出码为0。简单来说,就是避免用户直接通过shell登陆我的Linux机子。
    在Linux底下,每个程序执行完毕都会返回一个退出码给调用者,一般情况下0表示成功,其他值表明有问题,当然某些程序的退出码有特殊含义。有些shell下true可能是个内建命令,至少bash下是。(do nothing, successfully。Exit with a status code indicating success. NOTE: your shell may have its own version of true, which usually supersedes the version described here.  Please refer to your shell’s documentation for details about the options it supports.)。 相对应的命令是false,也是啥都不干,但退出码设置为1。

    到这里,服务器配置基本就欧了。


2) window端:

     如果上面设置的"wins support" 是"no"的话,跳过下面这步设置:
     控制面板->网络连接->LAN或高速Internet,找到你的LAN连接->右键属性->"TCP/IP" 协议->点击"属性" 按钮-> 点击 "高级..."->"WINS"-> "添加"->填入Linux的ip地址->"添加"->"启用 NetBIOS over TCP/IP"->重启Windows

    接着,可以映射网络驱动器:

    "我的电脑"-> "映射网络驱动器"->选择盘符->敲入 \\LUOCANWEI_SERVER\MyFiles

    注意: 如果不是静态ip,LUOCANWEI_SERVER可能得改为乖乖每次敲打ip了,即敲入\\<ip-address>\MyFiles
    完成。


参考:1 http://ubuntuforums.org/showthread.php?t=202605

           2 http://www.1987.name/686.html 

           3 https://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html

           http://www.samba.org/samba/

           5 http://zhidao.baidu.com/question/490153956.html

本文:http://blog.csdn.net/rayluoluo4/article/details/39718685


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值