> Source: [sk95447](https://support.checkpoint.com/results/sk/sk95447)

# sk95447 - How to extend SSH session timeout and allow commands to survive after the SSH session has closed

| Property | Value |
|----------|-------|
| Solution ID | sk95447 |
| Date Created | 2013-10-10 |
| Last Modified | 2022-12-28 |
| Technical Level | General |
| Products | Security Gateway, Security Management Server, Spark Firewall (Locally Managed), Multi-Domain Security Management Server |
| Versions | R81.20, R81.10 (EOS), R81.20, R81.10.X, R81 (EOS), R81.10 (EOS), R81 (EOS), R81 (EOS), R81.10 (EOS), R81.20 |
| OS | Gaia |

## Solution

It is sometimes necessary to allow a command to survive after the end of the SSH session.

For example, you run a command, such as a debug or packet capture, but it fails to capture data because the SSH session times out. Commands that run from an SSH session (such as PuTTY) terminate when the SSH session ends. This makes it difficult to run traffic captures or debugs for long periods of time.

There are two ways to address this:

### Method 1: Increase the session idle timeout

1. Log in to Gaia Clish.
2. Check the current Clish idle timeout. Run:

   **HostName> show inactivity-timeout**
3. Set the idle timeout of the current Clish session to maximal value (in minutes):

   **HostName> set inactivity-timeout 720**
   **Note:** To set it permanently, also run: **HostName> save config**` `  

4. Log in to Expert mode.
5. Check the current Bash idle timeout. Run:

   **[Expert@HostName]# echo $TMOUT**
6. Set the idle timeout of the current Bash session to some high value (in seconds):

   **[Expert@HostName]# export TMOUT=3600**

   **Notes:**
   * To unset the Bash session idle timeout completely, assign the value 0 (zero).
   * To set the desired Bash session idle timeout *permanently* , edit the **/etc/bashrc** file - modify the line  
     from  
     *export TMOUT=\`expr $IDLE \\\* 60\`*   
     to  
     *export TMOUT=Desired_Value_in_Seconds*

<br />

<br />

<br />

### Method 2: Force the process to ignore "hangup" when an SSH session ends.

When an SSH session ends, a "hangup" signal is sent to all of its child processes.  
There are two methods to prevent the signal:

*

  #### Method 2.1 Disown the process

  1. Enter a command, followed by the ***ampersand*** (\&) to place that command in the background.

     *Example*:

     ```
     [Expert@Host]# fw monitor -e "accept host(172.16.0.1);" -o /var/log/test.cap &
     [1] 27524
     ```

     Where "27524" is the Process ID (PID) of the *fw monitor* command.

     Verify this by running a *ps -auwx*" command. For example:

     ```
     [Expert@Host]# ps -auwx | grep "fw monitor"
     admin     27524  0.7  2.1  88268  21256 pts/2        Ss   Aug02   2:05 fw monitor -e accept host(172.16.0.1); -o /var/log/test.cap
     ```

  2. Disown the process (refer to [manual page](http://linux.die.net/man/1/disown)):

     **[Expert@HostName]# disown <PID>**

     In our example, the PID=27524:  
     *\[Expert@HostName\]# disown 27524*
     Ending te SSH session, or ending having the SSH session end because of a timeout will no longer send a hangup to this process. This is because it is no longer a child process of the SSH session.
  3. Open a new SSH session to this machine and manually kill the disowned process that still runs in the background:

     **\[Expert@HostName\]# kill \<PID\>**

     In our example, the PID=27524:  
     *\[Expert@HostName\]# kill 27524*
*

  #### Method 2.2: Set the process to ignore hangups

  This method leaves the process as a child of the SSH session, but causes it to ignore the "hangup" signal from SSH when it closes.
  1. Run the desired command prepended by "***nohup*** " and followed by the ***ampersand*** (\&) to place that command in the background:

     **[Expert@HostName]# nohup <Desired_Command> &**

     *Example*:

     ```
     [Expert@HostName]# nohup fw monitor -e "accept host(172.16.0.1);" -o /var/log/test.cap &
     [1] 30209
     nohup: appending output to 'nohup.out'
     ```

     **Notes**:
     * The output of the command is piped to the text file *nohup.out* that is created in the same directory, from which the entire command was run.
     * The SSH session can be ended with "exit" or can time out, but the hangup signal sent to this child process will be ignored.
  2. Open a new SSH session to this machine and manually kill the process that still runs in the background:

     **[Expert@HostName]# kill <PID>**

     In our example, the PID=30209:  
     *\[Expert@HostName\]# kill 30209*

<br />

***How to kill the process if you don't know the PID?***   
Run:*lsof nohup.out*

---

# Agent Instructions

This content is from the Check Point Support Center (https://support.checkpoint.com), the official knowledge base for Check Point cybersecurity products.

## Navigating This Knowledge Base

- **Complete index**: [llms.txt](https://support.checkpoint.com/llms.txt)
- **All SK articles**: [SecureKnowledge Sitemap](https://support.checkpoint.com/sitemaps/secureknowledge-sitemap-index.xml)
- **SK article URL pattern**: `https://support.checkpoint.com/results/sk/{skId}`
- **Markdown responses**: AI bot User-Agents automatically receive `text/markdown` content
