linux通过mount命令访问windows共享文件

Linux系统访问windows共享文件夹,可以通过mount命令实现。
语法如下:
mount -t cifs -o username="访问共享文件的账号",password="访问共享文件的密码" window机器的共享文件ip地址和共享目录 linux的挂载点
示例:
mount -t cifs -o username="Lenovo",password="ABC123" //192.168.31.12/shareTest /mnt/shareTest
说明:
-t cifs 代表访问类型是cifs格式, 如果共享的文件夹是windows的则使用这种类型即可;
-o是选项,代表后面时候选项;-o可以多次出现
本示例中,后面是完整的字符串,包含用户名和密码。
//192.168.31.12/shareTest 代表windows共享文件夹的网络地址;
/mnt/shareTest是linux系统的本地文件夹,需要事先建好,作为加载点。
如果挂载成功,进入到/mnt/shareTest路径下看到的内容就和windows机器上的shareTest路径的内容一致。
下面是完成的操作方式:
1.创建一个目录,作为挂载点。
mkdir /mnt/shareTest
2.然后执行mount挂载命令
mount -t cifs -o username="Lenovo",password="ABC123" //192.168.31.12/shareTest /mnt/shareTest
3.发现会出现以下错误,这是因为linux上面还没安装cifs工具导致的。
mount: wrong fs type, bad option, bad superblock on //192.168.31.12/shareTest,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program)
In some cases useful info is found in syslog - try
dmesg | tail or so.
4.安装cifs
yum install cifs-utils
安装完之后去到cd /sbin/, 查看是否有cifs.idmap cifs.upcall 这两个命令,这时候发现有了。然后重新执行第2步mount命令进行挂载,如果还是挂载失败出现第3步的提示,就执行yum install nfs-utils
命令安装nfs工具。
5.如果执行第2步的命令成功,则执行 cd /mnt/shareTest
命令进入到该目录查看文件,这时候就能直接看到windows共享出来的文件了。
注意事项:如果在执行挂载命令的时候遇到 mount error(13): Permission denied
错误
就是没权限引起的,如在执行mount命令的时候没有设置账号密码,需要输入密码。这时候看到的账号默认是linux的登录账号,该账号与windows的共享文件的账号不一致,这时候无论密码怎么输入也是验证失败。根本的解决办法就是在执行mount命令的时候同时设置账号密码,且保证账号密码与windows共享文件夹的账号密码一致即可。
取消挂载umount 命令
语法:umount 挂载点
示例:umount /mnt/shareTest/
在取消挂载的时候有时候会报如下问题:
umount: /mnt/shareTest: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
这是因为你已经进入到/mnt/shareTest路径下面了,只要不进入到/mnt路径就能执行成功,如下所示。
[root@localhost shareTest]# umount /mnt/shareTest/
umount: /mnt/shareTest: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@localhost shareTest]# cd ..
[root@localhost mnt]# cd ..
[root@localhost /]# umount /mnt/shareTest/
[root@localhost /]# cd /mnt/shareTest/
[root@localhost shareTest]# ls
[root@localhost shareTest]#




更多推荐
所有评论(0)