Clearing IDLE TTY Sessions in Junos

Reading Time: 2 minutes

This is going to be a quick post on how you can forcibly disconnect idle and/or other users by using their PID or TTY session.

This is very useful, when you have too many simultaneous concurrent connections (normally when you having some issue) or because of some dodgy connections you get from time to time, and your terminal gets timed out in the middle of configuring and you have to reconnect. To be then greeted with:

[[email protected] ~]$ ssh 10.1.0.243
Password:
--- JUNOS 14.1X53-D25.2 built 2015-04-01 01:53:36 UTC
{master:0}
[email protected]> edit 
Entering configuration mode
Users currently editing the configuration:
  marquk01 terminal p0 (pid 41263) on since 2015-05-04 11:22:50 UTC, idle 02:01:13
      {master:0}[edit firewall]
  marquk01 terminal p1 (pid 41306) on since 2015-05-04 12:02:30 UTC, idle 01:16:58
      {master:0}[edit]

If you’re like me and find this annoying. There is a simple way of; firstly, showing all the current concurrent session on the device and then how you can disconnect them.

To show all the user sessions that are on the switch, you can run the command show system users no-resolve:

[email protected]> show system users no-resolve 
fpc0:
--------------------------------------------------------------------------
 1:26PM  up 33 days,  6:56, 3 users, load averages: 0.00, 0.01, 0.00
USER     TTY      FROM                              [email protected]  IDLE WHAT
marquk01 p0       10.1.0.17                        11:22AM  2:03 -cli (cli)    
marquk01 p1       10.1.0.17                        12:02PM  1:19 -cli (cli)    
marquk01 p2       10.1.0.17                        1:24PM      - -cli (cli)

This command provides information on:

  • Connected Users
  • TTY session
  • IP address each user has connected from
  • Login Times
  • Idle Timer
  • User’s method of remote access

We can see that I have 3 sessions currently but only one is active, as 2 connection have IDLE times.

To clear to two session we can either use the TTY session number, shown in the output or by the process ID (pid).

To clear by the TTY session, I had to need to run the command request system logout terminal {TTY session} to disconnect the first idle session.

[email protected]> request system logout terminal p0
{master:0}
[email protected]> show system users no-resolve         
fpc0:
--------------------------------------------------------------------------
 1:27PM  up 33 days,  6:57, 2 users, load averages: 0.23, 0.06, 0.02
USER     TTY      FROM                              [email protected]  IDLE WHAT
marquk01 p1       10.1.0.17                        12:02PM  1:19 -cli (cli)    
marquk01 p2       10.1.0.17                        1:24PM      - -cli (cli)

The other method would be to clear the user’s pid number. You can find their pid either; in Operational mode, by using the TTY session number running the command show system processes | match {TTY session} (you will need to look for the pid with mgd process) or in Configuration mode, by running the command status:

[email protected]> show system processes | match p1 
41299  ??  Is     0:00.17 sshd: [email protected] (sshd)
41306  ??  Is     0:00.06 mgd: (mgd) (marquk01)/dev/ttyp1 (mgd)
41307  p1  Ss+    0:00.47 -cli (cli)

{master:0}
[email protected]> edit 
Entering configuration mode

{master:0}[edit]
[email protected]# status 
  marquk01 terminal p1 (pid 41306) on since 2015-05-04 12:02:30 UTC, idle 01:20:58
      {master:0}[edit]

Once I found the pid number, I ran the command request system logout pid {pid number} to disconnect the second idle session.

[email protected]> request system logout pid 41306

{master:0}
[email protected]> show system users no-resolve       
fpc0:
--------------------------------------------------------------------------
 1:32PM  up 33 days,  7:02, 1 user, load averages: 0.00, 0.02, 0.00
USER     TTY      FROM                              [email protected]  IDLE WHAT
marquk01 p2       10.1.0.17                        1:24PM      - -cli (cli)

And thatโ€™s how you clear idle TTY connections in Junos ๐Ÿ™‚

The following two tabs change content below.

Keeran Marquis

Network Engineer
Keeran Marquis is a Network Engineer. His main goal is to learn everything within the Networking field, pick up a little bit of scripting, be a poor man sysadmin and share whatever he knows! All Posts are his own views, opinions and experiences, no guarantees they will work for you but point you in the right direction ๐Ÿ™‚
Share this:
Share

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.