LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-17-2021, 10:15 AM   #1
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,336
Blog Entries: 3

Rep: Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731
Reverse tunneling SSH keys with port limitations on both ends?


I am looking to find a way to use public key options, or any other method, to forceably limit ports on both ends of a reverse tunnel over SSH.

If I set up a reverse tunnel initiated from system A to system B, where port 4406 on B is connected to port 3306 on A:

Code:
ssh -R 4406:localhost:3306 serverB.example.com
I can then limit the choice of port available on B by using the PermitListen option within the public key as recorded in system B's account's authorized_keys file.

Code:
$ hostname 
serverB.example.com

$ grep -w 4406 ~/.ssh/authorized_keys

restrict,port-forwarding,permitlisten="localhost:4406" ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCmE1i8zP2Edb+JJv0dYHwhn0d91cqJTrhT8AiiidE6GdfMQqQtwBQ5jcm+PLeJ5Fw6OGPMTKRGCRFXpvtPUfyI=
How do I then also limit the choice of ports on the other end of the connection? That is to say, limit which port the key can use on the originating system. I've experimented with the PermitOpen option but it is not relevant here because it affects only -L regular forwarding, not reverse forwarding. I expect I have missed something fairly obvious?
 
Old 04-19-2021, 09:29 AM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,378

Rep: Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757
I am not sure of the use case here. Are you saying that you wish to demonstrate that a user that is trusted with a key and has accessed system A should not be allowed to do something like set up a cron job to setup a tunnel with 'ssh -R 4406:localhost:5506 serverB.example.com'.

Perhaps firewall restrictions on outgoing connections on serverA?
 
Old 04-19-2021, 09:54 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,336

Original Poster
Blog Entries: 3

Rep: Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731
The use-case would be for an automated script using a key without a passphrase. There, I figure the more locked down the better as a reminder that the key is single-purpose. But, yes, there is trust involved either way.

The absence of a passphrase would be in contrast to setting up a one-off SSH agent just for that script and manually loading the key into the agent as needed.

Maybe rejecting all outbound ports on serverA, with a small subset allowed, would be one way, but seems fiddly on a system still a while away from transitioning from development to production.
 
  


Reply

Tags
permitlisten, port forwarding, reverse tunnel, ssh



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reverse Tunneling / Reverse port forwarding in SSH dynamics Linux - Networking 5 02-07-2017 07:19 AM
why do optical discs have minute limitations as well as size limitations? newbiesforever General 9 02-09-2014 04:35 AM
What is required for port based VLAN on both ends with no switch? sysslack_linux Linux - Networking 2 12-26-2011 04:09 AM
ssh tutorial, for reverse tunneling for vinagre & sftp manwithaplan Linux - Networking 1 11-02-2009 09:52 PM
LXer: Reverse SSH Tunneling LXer Syndicated Linux News 0 09-19-2008 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration