Solved

Secure tunnel using SSH to a backend FTP server

Posted on 2011-03-02
7
728 Views
Last Modified: 2012-05-11
Hi,

Is it possible to do this using SSH to the Linux Server so that the FTP Server is exposed on my Mac through the SSH tunnel?

Mac > Internet > Linux Server > Internal Network > FTP Server

Basically, I want to connect to the FTP server directly from my Mac (note that the FTP server is NOT on the front end Linux server)

Normally, I would do
ssh user@server.net
ftp ftp.internal.lan


Thanks
BT
0
Comment
Question by:brothertom
  • 4
  • 3
7 Comments
 

Author Comment

by:brothertom
ID: 35016313
I'm guessing we would also need to make changes to the iptables on the Linux Server to specific a port, say 4444 to port 23 on ftp.internal.lan
0
 
LVL 7

Accepted Solution

by:
rodness earned 500 total points
ID: 35017524
You can do this with SSH port forwarding:

sudo ssh -L 21:ftpserver.net:21 user@server.net
ftp localhost

Open in new window


This will connect you via ssh to user@server.net.  It will open port 21 (ftp) on the local system and forward connections to port 21 (ftp) on the ftpserver.  It needs to be run as root (sudo) because port 21 is privileged, and only root can open it.

Then you just ftp (or use cyberduck or whatever) with localhost as the address, and the connection is automatically forwarded to the desired computer.  Note that OTHER computers CANNOT connect to port 21 on your machine... you can only connect locally, for security reasons.  So you can't use this to just create a wide open tunnel for anyone hitting your machine through to the ftp server.  (This is a good thing.)

Alternately, if you don't want to use sudo:

ssh -L 4444:ftpserver.net:21 user@server.net
ftp -P 4444 localhost

Open in new window

This will open port 4444 locally instead, which doesn't require root (sudo) privilege.  You just need to specify that port for the ftp command.

0
 

Author Comment

by:brothertom
ID: 35018039
Thanks for your reply.  Your solution will allow FTP on the server via SSH, but the FTP server is actually hosted on a machine behind the front end server.

I think your technique will work, but I need to figure out how to direct the incoming FTP traffic (over SSH) to the backend ftp server.

Thoughts?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 7

Assisted Solution

by:rodness
rodness earned 500 total points
ID: 35018190
No, this enables a local port (on your Mac) to be redirected THROUGH the ssh server to the FTP server.  This is exactly what you asked for, to use the ssh server to expose FTP so that you can connect directly to the FTP server from your Mac.

This is because of the argument to -L:  21:ftpserver:21

The first argument is the local port (Mac). The second is the remote server, which is the FTP server, and finally the remote port.

Give it a try. :)
0
 

Author Comment

by:brothertom
ID: 35018714
OK, I get it - tried connection to ftp.microsoft.com

Get to login and password, but when doing ls, I get connection refused.  
Tried a couple of servers but same.  
Is port only port 21 used, or does port 20? need to be included somehow?
Got a vague memory of FTP using more than one port.

BT


ftp 127.0.0.1
Connected to 127.0.0.1.
220 Microsoft FTP Service
Name (127.0.0.1:user1): anonymous
331 Anonymous access allowed, send identity (e-mail name) as password.
Password:
230-Welcome to FTP.MICROSOFT.COM. Also visit http://www.microsoft.com/downloads.
230 User logged in.
Remote system type is Windows_NT.
ftp> ls
229 Entering Extended Passive Mode (|||13744|)
ftp: Can't connect to `127.0.0.1': Connection refused
200 EPRT command successful.
150 Opening ASCII mode data connection.
0
 
LVL 7

Assisted Solution

by:rodness
rodness earned 500 total points
ID: 35019179
Dammit.  You're right, I forgot about the passive connections.  While you can supply multiple -L commands to forward multiple ports, it's hard to predict the passive port that the server is going to tell you to connect on.  (In your case, 13744, which wasn't open on the local machine.)

Is it an option to run sshd on the ftp server?  Then you can simply forward port 22 instead of 21, and use sftp instead of ftp.

From googling, it doesn't look like there's an easy answer to this.  It's kind of why sftp has replaced ftp.... ftp over ssh tunnels is just not easy.  sftp was designed for this.


0
 

Author Comment

by:brothertom
ID: 35027026
I think the backend FTP server is just a dumb ftp box, but I'll see if it supports sftp (therefore sshd) and try that.

Thanks
BT
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can I roll-back a new iMac to an older OSX? 3 65
changing email : how to reload all of my data from Yahoo mail to Gmail 4 149
flash professional 3 31
MacBook Upgrade OS 6 27
The /etc/authorization file in Mac OS X 10.x can be used to control access to the various panes of the System Preferences amongst other things. It’s used by some of us Mac Sys Admin’s to give Standard Users access to System Prefs panes that only adm…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question