Tunneling SAMBA Through SSH

本文介绍如何通过SSH隧道从远程位置访问大学内的SAMBA服务器数据。提供了两种方法:一是命令行方式设置隧道并挂载共享文件夹;二是通过配置~/.ssh/config文件简化日常操作。

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

Tunneling SAMBA Through SSH

At the university we have a wide range of computers platforms we process data. We also have file servers consisting of several RAIDs holding up naby terabytes  of  data. The challenge that we were facing was to access all this data when we are away from campus. 

In a previous article I wrote about SSH tunneling and if you get lost reading this article you might want to check that one for basics. As in the previous article I'll provide two methods.

 

Method 1: From the Command line

We need to establish a SSH tunnel between the client (C, your laptop) and the secure server (S, SAMBA server) through the gateway (G). 

ssh -f -N -L 22000:address.of.secure.server:139 
 .gateway

 Above command establishes a tunnel between local port 22000 of the client (your laptop) and the SAMBA port (139) of the secure server (S).

Now we can mount the disk using the local port 22000 and the loopback address of "127.0.0.1".

Make sure that you have an empty folder ready to be used as mount location. 

smbmount //address.of.secure.server/shared.folder /local.mount.folder/ -o domain=domain.name,username=your.user.name,ip=127.0.0.1,port=22000 

That's it! Once you enter your password you should be able to see these files under the /local.mount.folder/. Let me explain the above command a little more in detail. 

smbmount: is the samba mount command for Ubuntu.  I prefer smbmount (mount.cifs) over mount here because I can use it without being root.

shared.folder: is the shared folder location on the secure SAMBA server. Make sure this folder is shared, and the SAMBA server is running. Otherwise this will not work for obvious reasons. If the reasons are not obvious ask your system administrator.

local.mount.folder: is the folder where you mount the share. If successful, you will be able to reach the files in this share through this location on your laptop. 

-o : is the option parameter. After this all parameters specify an option and its value.

domain: option sets the domain name for the secure samba server. 

username: option specifies your username on the secure samba server. You can specify the password with the "password" parameter but I prefer not to type my password on the command line. ;) See mount.cifs man page for other ways of specfying password if you don't want to enter it each time. 

ip: option sets the IP address of the server to connect to. Since we established a tunnel between localhost:22000 and secure.server:139, we use localhost. 

port: option sets the port number to connect to on the specified IP address.  This is the port we specified above in the first command.

 Method 2: Using the ~/.ssh/config File

I like to specify common tunnels in the "~/.ssh/config"  file to reduce the number of daily key strokes. For details of this section refer to the previous article: SSH Tunneling

 Add the following lines to your ~/.ssh/config file.

Host Gateway
Hostname address.for.the.gateway
LocalForward 22000 address.of.SAMBA.server:139 
Host SambaServer
Hostname localhost
port 22000

You can see the similarities of the above section with the previous article. It has exactly the same format, the only difference is that we are connecting to port 139 (SAMBA server port) on the secure.server instead of 22 (SSH port).

Once you set your configuration file, you can set the tunnels as before:

ssh -N -f Gateway

And you can connect to the SAMBA Server with the following command:

smbmount //SambaServer/path/to/samba/folder /local.mount.folder/ -o domain=your.domain.name,username=your.user.name,ip=127.0.0.1,port=22000

 Enter the password, and you should be all set!

On a side note I strongly suggest that you also specify the user id (uid) and the group id (gid) for the files on the share by specifying these options. Since SAMBA does not fully support files owned by different users, it is likely that this will save you from some headache in the future.

Related Articles

  1. Samba with SSH, Mark Williamson
  2. How-to mount NFS through a SSH Tunnel, Andrew Uzilov, 28 Mar 2006
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值