(1),使用linux访问windows下的共享文件。运行samba,然后ctrl+l;在提示框里面这样输入:smb://windows的ip地址。例:smb://192.168.0.2/
(2),Linux下通过smbclient访问windows共享目录
1,列出某个IP地址所提供的共享文件夹smbclient-L198.168.0.1-Uusername-Wdomain(会提示输密码)smbclient-L198.168.0.1-Uusername%password-Wdomain
2,像FTP客户端一样使用smbclientsmbclient//192.168.0.1/tmp-Uusername-Wdomain(会提示输密码)smbclient//192.168.0.1/tmp-Uusername%password-Wdomain
执行smbclient命令成功后,进入smbclient环境,出现提示符:smb:/>这里有许多命令和ftp命令相似,如cd、lcd、get、megt、put、mput等。通过这些命令,我们可以访问远程主机的共享资源。
3,直接一次性使用smbclient命令smbclient-c"ls"//192.168.0.1/tmp-Uusername%password和smbclient//192.168.0.1/tmp-Uusername%passwordsmb:/>ls功能一样的
例,创建一个共享文件夹smbclient-c"mkdirshare1"//192.168.0.1/tmp-Uusername%password如果用户共享//192.168.0.1/tmp的方式是只读的,会提示NT_STATUS_ACCESS_DENIEDmakingremotedirectory/share1
(3),挂载windows共享目录(smbfs、cifs)Linuxkernel2.6.29之后,smbfs将从内核中取消,将被cifs(CommonInternetFileSystem)代替。
①使用smbfs文件系统Linux客户端要连接samba或windows文件服务器时,需使用smbmount或mount指令:
【mount的用法】mount-tsmbfs-ousername=用户名,password=密码,-l//ip地址/共享文件夹名挂载点或mount-tsmbfs-ousername=用户名,password=密码,-l//计算机名/共享文件夹名挂载点或mount-tsmbfs-o//ip地址或计算机名/共享文件夹名挂载点
【例】:mount-tsmbfs-ousername=administrator,password=password//sambaserver/sharefolder/mnt/sharemount-tsmbfs-ousername=aaa%bbb//sambaserver/sharefolder/mnt/sharemount-tsmbfs-ousername=administrator,password=password//Windows_OS/sharefolder/mnt/sharemount-tsmbfs-ousername=aaa%bbb//Windows_OS/sharefolder/mnt/share
【smbmount的用法】smbmount-ousername=用户名,password=密码,-l//ip地址或计算机名/共享文件夹名挂载点或smbmount//ip地址或计算机名/共享文件夹名挂载点
【例】:smbmount//sambaserver/sharefolder/mnt/share-ousername=administrator,password=passwordsmbmount//sambaserver/sharefolder/mnt/share-ousername=administrator%passwordsmbmount//Windows_OS/sharefolder/mnt/share-ousername=administrator,password=passwordsmbmount//Windows_OS/sharefolder/mnt/share-ousername=administrator%password
使用mount命令完成,如(必须给出具体的windows共享名,可以通过前面介绍的smbclient获得共享名):#mount-oguest-tsmbfs//192.168.0.20/linux/mnt/win_share
★附加说明
1,为了能正确显示中文,以utf8为locale的用户(如果使用Ubuntu或Fedora,默认就是utf8的locale)加入以下选项:codepage=cp936和iocharset=utf8,即mount命令为:#mount-oguest,iocharset=utf8,codepage=cp936-tsmbfs//192.168.0.2/linux/mnt/win_share之所以这样写,是因为远端使用的编码是cp936,而本地使用的是utf8。
2,以gbk为locale的用户则#mount-oguest,iocharset=cp936,codepage=cp936-tsmbfs//192.168.0.2/linux/mnt/win_share这样写的原因是远端和本地都是cp936
[注意]:1.指定uid或gid参数,也能指定用户的身份(uid=后面可接uid号或用户名),如:smbmount//test/d/mnt/d-ouid=grind2.smbmount也能写作mount.smbfs,这是个符号链接;3.smbmount的参数必须写在最后,而mount的参数位置能变化;4.由于//sambaserver/d格式能表明是要mount上smbfs,所以mount的-tsmbfs参数能省掉;5.如果命令行中不加入密码,下一行中系统会提示你输入;
【使用例】:
1.首先在windows上共享一个目录,如:共享了目录share,用户和密码是:administrator/abc123
2.在linux机器上,在/mnt目录下建立一个win目录,使用root用户,执行下面命令:
mount-tsmbfs-ousername=administrator,password=abc123//192.168.1.1/share/mnt/win
这是你就可以在/mnt/win看到了windows上共享的数据了。
3.自动挂载,编辑vi/etc/fstab,在最后面加入:
//192.168.1.1/share/mnt/winsmbfsdefaults,auto,username=administrator,password=abc12300
这样linux机器重新启动都可以自动挂载windows上的共享目录
②使用cifs文件系统
安装apt-getinstallcifs-utilsORyuminstall–ycifs-utils.x86_64
1.执行命令mount实现cifs
2.重启系统的时候自动mount,将下面命令行添加到/etc/fstab里。
添加完成后执行:sudomount-a
例:1,把samba服务器或windows系统的共享文件,挂载到samba客户端。mount-tcifs-ousername="root",password="123456"//10.10.04.15/test/mnt/share/