LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-29-2021, 02:24 PM   #1
fender1988
LQ Newbie
 
Registered: Oct 2020
Posts: 1

Rep: Reputation: Disabled
Question Looking for an application to automate ssh tunnels based on remote configuration?


Hey there,

I have a handful of cases where I start some application on a remote server (like a Jupyter notebook), start an ssh tunnel to forward a port from the remote to my local machine, and then pop open firefox to interact with the application. At the moment I have a script that automates starting the application and building the tunnel command, but I basically take this output and copy and paste it into a local terminal before I start working.

```
##########################################################

For MacOS or Linux, use this command to create SSH tunnel:

ssh -N -L localhost:<local-port>:<internal-server>:<remote-port> <user>@<server>

Then use this URL to access the application:

http://localhost:<local-port>

##########################################################
```

I'm wondering if someone else has written a cli application to automate port setup and even application launching to utilize said port? I imagined having a standard location (~/.config/forward/) on the remote that stores config files of applications that can be used this way.

Thanks!
 
Old 12-02-2021, 12:45 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,839

Rep: Reputation: 5972Reputation: 5972Reputation: 5972Reputation: 5972Reputation: 5972Reputation: 5972Reputation: 5972Reputation: 5972Reputation: 5972Reputation: 5972Reputation: 5972
Belated welcome to LinuxQuestions.

You can setup the tunnel(s) just by using a config file in your ~/.ssh directory on the client computer like:
Code:
host nickname
     hostname IP_address or server_name
     user remote_username
     port xxxx (if not using 22)
     localforward localport internal_server:remote-port
     IdentityFile ~/.ssh/private_key (if using keys)
To connect just run:
ssh nickname

You can create a script to run that command and then start firefox http://localhost:localport

Last edited by michaelk; 12-02-2021 at 12:58 PM.
 
Old 12-03-2021, 03:52 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,399
Blog Entries: 3

Rep: Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778
Quote:
Originally Posted by michaelk View Post
You can create a script to run that command and then start firefox http://localhost:localport
You can even do that via ~/.ssh/config as well. The following connects Firefox to port 9999 on the remote system using a tunnel from port 8888 on the local system:

Code:
Host nickname
     HostName server.example.com
     User fender1988
     Port 22
     LocalForward  8888 localhost:9999
     IdentityFile ~/.ssh/private_key
     PermitLocalCommands yes
     LocalCommand firefox --new-tab http://localhost:8888/
Firefox gets launched upon successful login to the remote system.

For now -N is needed when you launch it.

Code:
ssh -N nickname
Very recent OpenSSH clients will allow SessionType to be set in the configuration file so that -N is not needed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
SSH-Tunnels, Firewall, VNC bojo Linux - Security 3 03-16-2006 05:08 AM
Creating a router out of SSH Tunnels. Technoslave Linux - Networking 1 10-04-2004 06:07 PM
SSH tunnels and VNC, yet again. Edaph Linux - Security 7 05-23-2004 09:55 AM
Automatic SSH Tunnels fearofcarpet Linux - Software 1 12-04-2003 11:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:42 PM.

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