LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-27-2014, 03:15 PM   #1
marcelp1
LQ Newbie
 
Registered: Nov 2010
Distribution: Debian
Posts: 29

Rep: Reputation: 1
SSH Reverse Tunnel - ~/.ssh/config - PHP


My dads Laptop running Wheezy 64-bit and is behind NAT / Firewall.

I need sometimes connect the the machine over SSH to troubleshoot this or the other,
when TeamViewer does not work.

The usual SSH Reverse Tunnel he creates from his Laptop to remote SSH Server works the long way:


Create Authorized Keys for password less login:
ssh-keygen -t ecdsa -b 521
ssh-copy-id -i ~/.ssh/id_ecdsa.pub "my-Server@xxx.xxx.xxx.xxx -p 54321"
or
scp -P 54321 ~/.ssh/id_ecdsa.pub my-Server@xxx.xxx.xxx.xxx:.ssh/authorized_keys


his-Laptop@xxx.xxx.xxx.xxx:12345
my-Server@xxx.xxx.xxx.xxx:54321
my-Laptop@@xxx.xxx.xxx.xxx:22222


SSH Reverse Tunnel:
ssh -R 11111:localhost:12345 my-Server@xxx.xxx.xxx.xxx -p 54321

Then I connect from my-Laptop to the remote SSH server:
my-Server@xxx.xxx.xxx.xxx -p 54321

And from my-Laptop connect to SSH tunnel connection on that SSH server:
ssh his-Laptop@localhost -p 11111



I have found that I can store on his-Laptop the whole SSH Reverse Tunnel command into:
vim ~/.ssh/config
########################################################################
Host reverse
HostName xxx.xxx.xxx.xxx
Port 54321
RemoteForward 11111 localhost:12345
User my-Server
########################################################################
And "ssh reverse" on his-Laptop works


Then on my-Laptop create:
vim ~/.ssh/config
########################################################################
Host my-Server
HostName xxx.xxx.xxx.xxx
Port 54321
User my-Server
########################################################################
"ssh my-Server" from my-Laptop does work


And on my-Server the same:
########################################################################
Host his-Laptop
HostName localhost
Port 11111
User his-Laptop
########################################################################
"ssh his-Laptop" works as well


But, I wanted to ask, is there any way that when he types "ssh reverse" on his-Laptop
the Terminal windows will either close, or go into background (execute the command and close)?

Or even better, have a PHP script that would do all this if he opened
his web browser and clicked on pre-set link either stored locally or on my-Server?

Or would cron job that would connect once his-Laptop starts be better option?
 
Old 05-28-2014, 01:49 AM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,307
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
But, I wanted to ask, is there any way that when he types "ssh reverse" on his-Laptop
the Terminal windows will either close, or go into background (execute the command and close)?
Probably the easiest way is to give him an icon that runs a terminal executing the script minimized.
There's no taint checking in PHP, I wouldn't have him type anything into a terminal that gets passed to PHP without an error checking script to clean up the input.
 
  


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
[SOLVED] ssh reverse tunnel vib150 Linux - Networking 16 10-27-2013 10:22 PM
rsync via reverse ssh tunnel dexznrl Linux - Software 1 02-08-2011 09:38 AM
[SOLVED] Reverse SSH tunnel edan Linux - Security 3 07-14-2010 10:37 PM
SSH reverse tunnel (lo only? why not eth0) Dinomight Linux - Networking 3 08-17-2006 10:44 PM
Reverse SSH Tunnel sniggleflop Linux - Security 1 10-13-2002 02:24 PM


All times are GMT -5. The time now is 06:37 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration