Skip to main content

All Questions

Filter by
Sorted by
Tagged with
1 vote
1 answer
473 views

Saving the dynamically allocated port of SSH tunnel

There is already a great question and answer here, but I have a different case. I create a tunnel with the following command: $ ssh -N -R 0:192.168.0.16:80 [email protected] Allocated port 35007 for ...
Dmytro Soltusyuk's user avatar
2 votes
1 answer
2k views

Command not found when executing in remote server using shell script

I am trying to automate a few steps that I need to execute in a remote linux machine from my local ubuntu computer. My shell script is as follows :- #!/bin/sh ssh XYZ ' qlogin -l cuda=1 ' When I ...
Echo's user avatar
  • 121
1 vote
1 answer
689 views

How to run a local script with whitespace in arguments on a remote machine through multiple SSH?

Similar to my question here, except with multiple ssh, and similar to this question but with white space in the arguments... I would like to run a local script, test.sh, on a remote server via ...
Jacob Stern's user avatar
0 votes
1 answer
353 views

Automate SSHing into multiple connections with script

I want to ssh through three different servers. First one uses a password, second one doesn't and the third and final one has a different password than the first. Only the first one needs a username. ...
vic's user avatar
  • 103
1 vote
1 answer
386 views

setup consistent tunnel between two hosts wirh dynamic IPs

I would like to setup a constant ssh tunnel between two hosts. Now it becomes tricky as both hosts may change their IPs (not at the same time though). My idea to overcome this is to have two reverse ...
stdcerr's user avatar
  • 2,099
3 votes
1 answer
3k views

Use bash EXIT trap to confirm or cancel ctrl+d [duplicate]

Is there a simple way to require confirmation before logging out of a shell, and to prevent the shell from exiting if confirmation is denied? This would be useful to avoid accidentally terminating an ...
thinkmassive's user avatar
0 votes
1 answer
1k views

Probe SSH connection and detect ssh disconnect or logout

I'am running a script to connect to another host (via ssh) and it's doing some deployment work. I need to detect the ssh connection is closed/or interrupted, then need to execute a command to delete ...
Tharanga Abeyseela's user avatar
3 votes
1 answer
1k views

How to avoid piping awk to awk?

I have written the following script, which runs from my user's crontab, parses ~/.ssh/config for SSH port forwards, and automatically connects them if the Host line ends with "remote," "local," or "...
Q23's user avatar
  • 433
4 votes
1 answer
2k views

Predicting the PID of previously started SSH command

This is the weirdest thing. In a script, I start an SSH tunnel like so: ssh -o StrictHostkeyChecking=no -fND 8080 foo@bar This starts an ssh instance that goes into the background, and script ...
Malte Skoruppa's user avatar
3 votes
1 answer
313 views

Programmatically / dynamically adjust SSH session port forwards

I have a workflow where I am trying to do the following: For a given existing SSH session, access the remote machine and perform a process from which a port is returned (e.g. a remote daemon has ...
Fred Concklin's user avatar
2 votes
1 answer
1k views

Cron job running but not establishing tunnel

I have a script which establishes a reverse tunnel on an endpoint HostB. It looks like this: cat tun.sh #!/usr/bin/env bash # Test code /usr/bin/ssh -V 1> /home/userA/bin/tun.stdout 2> /home/...
Einar's user avatar
  • 281
19 votes
5 answers
6k views

Determine dynamically allocated port for OpenSSH RemoteForward

Question (TL;DR) When assigning ports dynamically for remote forwarding (a.k.a. -R option), how can a script on the remote machine (for instance sourced from .bashrc) determine which ports were ...
Bananguin's user avatar
  • 8,140
7 votes
1 answer
14k views

start autossh reverse tunnel automatically when network comes up

I connect from my home PC thru an Internet server I own to a restricted client (that I also own) using a reverse ssh tunnel. I have a script that sets up the restricted client to middleman leg of ...
MountainX's user avatar
  • 18.9k