Solved

Secure tunnel using SSH to a backend FTP server

Posted on 2011-03-02
7
736 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ruckus Zoneflex 7982 multiple SSIDs disconnects 11 95
facebook change 4 96
Me. Patrol Video app on a Mac 3 81
Hyperlinks Don't Open in Office 2011 for Macintosh Powerpoint 1 80
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…
Syslogd is a utility that traps and logs messages sent by running processes. It is configured with the syslog.conf file, which consists of lines containing a pair of fields: "the selector field which specifies the types of messages and priorities to…
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 …

752 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