Linux挂载Windows文件夹

74 篇文章 1 订阅
# sudo mount -t cifs \
-o user=username \ //Windows用户名
-o uid=myname,password=pass \ //Linux用户名,密码
-o gid=users \
-o defaults \
$mount_source \  //share/src_dir
$mount_point \ //dest_dir
-o nounix \
-o noserverino

举例

#!/bin/bash
#before mount,you should set the 4 item below

#1.your chian domain account,eg *wx*****
mount_user=china/ThomasZhang

#2.you account for linux
myname=zxc

#3.the dir you shared on your windows machine,the ip is windows ip
mount_source=//share/hg_10.0

#4.the path on linux
mount_point=/home/$myname/hg_10.0

if [ ! -d $mount_point ] ; then
echo "create directory $mount_point"
mkdir -p $mount_point
fi

sudo mount -t cifs \
-o user=$mount_user \
-o uid=$myname \
-o gid=users \
-o defaults \
$mount_source \
$mount_point \
-o nounix \
-o noserverino 

if [ $? = 0 ] ; then
echo "success mount to $mount_point :-)"
exit 0
else
echo "mount $mount_source fail."
exit 1
fi

报错

mount: /mnt: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.

解决办法:

apt-get install cifs-utils
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在 Linux 上自动挂载 Windows 共享文件夹,你需要使用 CIFS (Common Internet File System)协议。CIFS 可以让 Linux 访问 Windows 文件共享。 以下是在 Linux 上自动挂载 Windows 共享文件夹的步骤: 1. 安装 cifs-utils: ``` sudo apt-get update sudo apt-get install cifs-utils ``` 2. 创建一个目录,用于挂载 Windows 共享文件夹: ``` sudo mkdir /mnt/windows-share ``` 3. 编辑 /etc/fstab 文件,添加下面一行: ``` //WINDOWS_HOSTNAME/SHARE_NAME /mnt/windows-share cifs credentials=/home/YOUR_USERNAME/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0 ``` 其中,WINDOWS_HOSTNAME 是 Windows 主机的名称或 IP 地址,SHARE_NAME 是共享文件夹的名称。你需要将 YOUR_USERNAME 替换为你的用户名。 4. 创建一个包含 Windows 用户名和密码的文件,用于自动登录: ``` touch ~/.smbcredentials chmod 600 ~/.smbcredentials echo "username=WINDOWS_USERNAME" >> ~/.smbcredentials echo "password=WINDOWS_PASSWORD" >> ~/.smbcredentials ``` 将 WINDOWS_USERNAME 和 WINDOWS_PASSWORD 替换为你的 Windows 登录凭据。 5. 使用 mount 命令测试挂载: ``` sudo mount -a ``` 如果没有错误提示,就说明挂载成功了。 6. 重新启动 Linux,检查共享文件夹是否自动挂载: ``` ls /mnt/windows-share ``` 如果能够列出共享文件夹中的文件,就说明自动挂载成功了。 注意:如果你的 Windows 计算机使用的是 Windows 10 或更高版本,请确保在 Windows 上启用了 SMBv1 协议。你可以通过控制面板中的"程序和功能"来启用 SMBv1。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值