When you need only port forwarding, you can try if you disable starting a shell at all, and disable allocating a pseudo-terminal. Then the terminal can no longer be idle. :-)
If your ISP does not allow this, you can run a script like this in your shell session
while sleep 60; do
echo "Still there"
done
so that the terminal shows activity and it should not be logged out.
But it depends on the operating system they are using which option will help. You did not tell us, did you? uname -a
is your friend.
The official way to send environment variables from client to server is through SendEnv
and AcceptEnv
. The problem is that you need root access on the server to configure AcceptEnv
. Most servers are configured to accept no or only a few predetermined variables.
I found two tricks to send environment variables from client to server, both work without needing root access on the server.
trick one:
ssh -t server SSH_ORIGIN=$USERNAME@$HOSTNAME bash
this will connect to server and then execute the command SSH_ORIGIN=$USERNAME@$HOSTNAME bash
, with $USERNAME
and $HOSTNAME
already replaced on the client side. then, on the server side, you can further process the information contained in the variable SSH_ORIGIN
.
the -t
is needed otherwise bash will be started on the server without a tty (try it, you will see).
a slight modification will allow to pass the information transitively down a longer ssh chain.
ssh -t server SSH_ORIGIN=$USERNAME@$HOSTNAME:$SSH_ORIGIN bash
discussion:
- bash is started as an interactive non-login shell (
.profile
is not read).
- bash is run twice (
.bashrc
is read twice). once by sshd and once by the user command.
- it will always start bash, ignoring your default shell on the server.
trick two:
first you must generate a ssh key and transfer that to ~/.ssh/authorized_keys
on the server. then prepend the line with command="$SHELL"
. see the sshd manpage for more information on this.
connect to ssh server using the command:
ssh -t server SSH_ORIGIN=$USERNAME@$HOSTNAME
this will connect to the server but this time the variable assignment is not executed. instead, the string is stored in the environment variable $SSH_ORIGINAL_COMMAND
. then the command provided in ~/.ssh/authorized_keys
is executed. once you are in the shell you can process the information contained in $SSH_ORIGINAL_COMMAND
.
as above, you can make this transitive:
ssh -t server SSH_ORIGIN=$USERNAME@$HOSTNAME:$SSH_ORIGIN
discussion:
- it will start the default shell on the server.
- it will always start the default shell on the server. any command you give to the ssh command will be ignored and stored in
$SSH_ORIGINAL_COMMAND
. if you want to execute a command over ssh you can use a different ssh key or have your shell init file to detect and execute $SSH_ORIGINAL_COMMAND
.
Best Answer
Is it bash's TMOUT, or ssh? If it's TMOUT, there are a couple options listed here.
https://stackoverflow.com/questions/25675598/getting-kicked-out-of-openshift-server-after-a-while/25689720#25689720
Or
https://unix.stackexchange.com/questions/222283/read-only-tmout-variable-workaround-to-disable-automatically-exit-shell-when-t
-Erik