ubuntu挂载局域网共享文件

本文介绍了如何在Ubuntu系统中安装Samba文件系统和客户端,并详细指导了通过CIFS挂载网络共享文件夹的过程。包括配置静态IP地址、创建挂载点、使用命令行进行挂载和卸载等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

感谢dbott67


原文地址:http://ubuntuforums.org/showthread.php?t=280473


HOWTO: Mounting SMB/CIFS Shares


A few of the downsides on the Nexstar LX NAS device that I purchased is that:

1. It does not support CIFS

2. It does not support SATA drives (IDE only)

3. It is 10/100 Mbps (no gigabit)

4. It does not have any fault tolerance.

It is, however, an inexpensive device that can be used to share data among many computers. Anyhow, I have been in the process of upgrading my home network to gigabit and wanted to purchase a better NAS device that had some redundancy & expandability, as well as support for gigabit, CIFS and SATA drives (hot-swappable, no less). I ended up purchasing a Netgear (formerly Infrant) ReadyNAS NV+ 4250 and am providing an update to my original instructions using CIFS rather than smbfs:

Steps 1 and 2 remain the same.

In step 3, test mount the share using CIFS as noted:

Code:

dbott@gutsy:~$ sudo mount -t cifs //192.168.1.2/Music /home/dbott/Music -o iocharset=utf8,file_mode=0777,dir_mode=0777 


Step 4 remains the same.

Step 5, add the mount point(s) to your /etc/fstab file:

Code:

//192.168.1.2/Music /home/dbott/Music cifs credentials=/root/.credentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0 

//192.168.1.2/dbott /home/dbott/Data cifs credentials=/root/.credentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

//192.168.1.2/Archive /home/dbott/Archive cifs credentials=/root/.credentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0



The only issue that I encountered was with regards to UIDs. My user account on Ubuntu (dbott) has a UID of 1000, while my user account on the NAS has a UID of 1004. To fix this, I changed my Ubuntu UID to match the UID on the Netgear NAS using the following command:

Code:

[quote]sudo usermod --uid 1004 dbott[/quote]

After a couple of minutes and a reboot, everything was working properly.

Original Post: October 2006

I purchased a NexStar LX NAS device and wanted to mount some of the shares on my linux computers. I configured my NAS device with a static IP (192.168.1.2) and created a number of shares to store my data. This process can be used to mount any SMB or Windows shared folder:

1. Install 'smbfs' & 'smbclient' (Samba File System & Samba client)

Code:

sudo apt-get install smbfs smbclient


After installing the above, issue the command smbclient -L 192.168.1.2 -U% to generate a list of available shares (replace 192.168.1.2 with the IP or name of your SMB server):

Code:
dbott@thedrake:~$ smbclient -L 192.168.1.2 -U% 


2. Create new folder for the 'mount point'. In my case, I wanted the shared music folder to be mounted to the following location /home/dbott/music

Code:

cd ~ mkdir music 


3. Mounting the share from the command line (to verify that it works):

Code:

sudo smbmount //192.168.1.2/Music /home/dbott/music -o username=dbott,password=mysecretpassword,iocharset=utf8 


4. Un-mounting the share from the command line:

Code:
sudo smbumount /home/dbott/music 


5. Add the mount point to fstab (making it 'automatic'):

The unsafe way (fstab is world-readable, meaning that anyone can see your SMB username and password):

Code:

//192.168.1.2/Music /home/dbott/music smbfs auto,username=dbott,password=mysecretpassword,uid=1000,umask=000,user 0 0 

The better way (storing your username & password in a file only readable by root):

Code:

//192.168.1.2/Music /home/dbott/music smbfs auto,credentials=/root/.credentials,uid=1000,umask=000,user 0 0 


/root/.credentials is a text file that contains your smb username and password.

To create the file, type:

Code:

sudo gedit /root/.credentials 


and add the following text:

Code:

username=your_smb_username password=your_smb_password 


Now, make the file only readable by root:

Code:

sudo chmod 600 /root/.credentials 


6. At this point, you can either reboot or reload your fstab:

Code:

sudo shutdown -r now 


Code:

sudo mount -a 7. 


Now, when I browse to /home/dbott/music, I have access to all the shared MP3s on my NAS device.

-Dave
### Ubuntu系统中挂载网络共享文件夹 #### CIFS协议下的挂载操作 为了能够在Ubuntu上成功挂载基于CIFS协议的Windows或其他支持SMB/CIFS服务设备上的共享文件夹,需先确认已安装`cifs-utils`这一必要的软件包。这可以通过执行命令 `sudo apt install cifs-utils` 来完成[^1]。 一旦确保了上述工具的存在,下一步便是实际执行挂载动作。此过程涉及指定目标位置以及提供认证信息给远程服务器。具体来说,可以采用如下所示的命令形式: ```bash sudo mount -t cifs -o username=<用户名>,password=<密码> //<远程主机IP>/<共享路径> /<本地挂载点> ``` 这里需要注意的是,应替换掉尖括号内的占位符为真实的值;例如,如果要连接到位于局域网内地址为`192.168.0.100`的一台机器,并且该机有一个名为`data`的共享文件夹,则完整的命令可能是这样的: ```bash sudo mount -t cifs -o username=myuser,password=mypassword //192.168.0.100/data /mnt/mysharedfolder ``` 对于安全性考虑,建议不直接在命令行输入明文密码,而是利用凭证文件或者交互方式获取登录凭据[^3]。 #### NFS协议下的挂载操作 当涉及到NFS(Network File System)类型的共享资源时,虽然两者都属于网络文件系统的范畴,但是其配置和使用方法有所不同。通常情况下,不需要额外安装客户端组件即可实现基本功能,因为大多数现代Linux发行版默认包含了对NFS的支持。 假设有一台运行着NFS服务并开放了一个特定目录作为公共读写区域的服务端,那么可以在Ubuntu终端里键入下面类似的指令来进行临时性的快速挂载: ```bash sudo mount <nfs-server-ip>:<exported-directory-path> <local-mount-point> ``` 比如,针对一台具有静态IP地址`192.168.1.2`并且导出了根下`/srv/nfsshare`路径供外部访问的情况而言,相应的挂载语句会变成: ```bash sudo mount 192.168.1.2:/srv/nfsshare /mnt/remoteshared ``` 值得注意的是,在正式环境中往往还需要编辑/etc/fstab文件以便于开机自动加载这些远端存储空间,同时也要注意防火墙设置和其他可能影响通信的因素[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值