Monday, 28 November 2016

Pause an ssh session


This is a short read but most definitely a neat trick. While working on systems as part of daily routine we frequently traverse systems logging into one server, then another & back & so on & so forth. Time & again we come across a situation wherein we just logged into a server & remembered that we needed something from the source server & we go back to the source server & have to follow the login process completely again.
There is a neat trick which allows you to temporarily suspend a ssh connection, do your work on the source & log back in when you are done.
Here's the demo.

I'm logged into my source system centops as root user.


Now I login to another system cclient1 & i just remembered something that I need to check on system centops. Instead of logging out & logging back in, I'll suspend my ssh session by entering the following command sequence. ~ followed by ctrl+z.


Just a note here. The ~ character isn't visible on screen when we type it. We are able to view the complete command we typed post execution.
So, our ssh connection has been suspended & we are back to our source server. To make sure that the session still exists in suspended state we can use the jobs command & check the PID in the ps -ef output.


To resume the session all we have to do is to use the fg command followed by % & the jod id next to it.


No comments:

Post a Comment

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...