Login Settings
Junos OS enables you to define various settings for users when they log in to a device. You (the system administrator) can configure:
- Messages or announcements to display before or after login
- Whether to display system alarms upon login
- Login tips
- Time-based user access
- Timeout values for idle sessions
- Limits on the number of login attempts
- Whether to lock a user account after a number of failed authentication attempts
Display a System Login Announcement or Message
Sometimes you want to make announcements only to authorized users after they log in to a device. For example, you might want to announce an upcoming maintenance event. At other times, it might be appropriate to display a message, such as a security warning, to any user that connects to the device.
By default, Junos OS does not display any login message or
announcement. You can configure the device to display a login message or
announcement by including the message
statement or the
announcement
statement at the [edit system
login]
hierarchy level. Whereas the device displays a login
message after a user connects to the device but before the
user logs in, it displays an announcement only after the user
successfully logs in to the device.
You can format the message or announcement text using the following special characters. If the text contains spaces, enclose it in quotation marks:
-
\n—New line
-
\t—Horizontal tab
-
\'—Single quotation mark
-
\"—Double quotation mark
-
\\—Backslash
To configure an announcement that only authorized users can see and a message that any user can see:
Display System Alarms Upon Login
You can configure Juniper Networks devices to execute the show system
alarms
command whenever a user in a given login class logs in to the
device.
To display alarms whenever a user in a specific login class logs in to the device:
When a user in the given login class logs in to the device, the device displays the current alarms.
$ ssh user@host.example.com Password: --- JUNOS 21.1R2.6-EVO Linux (none) 4.8.28-WR2.2.1_standard-g3999f55 #1 SMP PREEMPT Fri Jun 4 00:19:58 PDT 2021 x86_64 x86_64 x86_64 GNU/Linux 2 alarms currently active Alarm time Class Description 2021-07-22 15:00:14 PDT Minor port-1/0/0: Optics does not support configured speed 2021-07-22 15:00:14 PDT Minor port-1/0/1: Optics does not support configured speed
Configure Login Tips
You can configure the Junos OS CLI to display a tip whenever a user in the given login class logs in to the device. The device does not display tips by default.
To enable tips:
When you configure the login-tip
statement, the device displays a
tip to any user in the specified class who logs in to the device.
$ ssh user@host.example.com Password: JUNOS tip: In configuration mode, the [edit] banner displays the current location in the configuration hierarchy. user@host>
Configure Time-Based User Access
You can configure supported Juniper Networks devices to enforce time-based user access for users in a given class. Time-based user access restricts the time and duration of user logins for all users belonging to the class. You can restrict user access based on the time of day or day of the week.
To restrict user access to certain days or times, include the following statements at the
[edit system login class class-name]
hierarchy
level:
-
allowed-days
—Configure user access on specific days of the week. -
access-start
andaccess-end
—Configure user access between the specified start time and end time (hh:mm).
To configure time-based user access:
-
Enable access on specific days of the week.
[edit system login class class-name] user@host# set allowed-days [ day1 day2 ]
For example, to configure user access for the
operator-round-the-clock-access
login class from Monday through Friday without any restriction on access time:[edit system login class operator-round-the-clock-access] user@host# set allowed-days [ monday tuesday wednesday thursday friday ]
-
Enable access at specific times of the day.
[edit system login class class-name] user@host# set access-start hh:mm user#host# set access-end hh:mm
For example, to configure user access for the
operator-day-shift-all-days-of-the-week
login class from 8:30 AM through 4:30 PM on all days of the week:[edit system login class operator-day-shift-all-days-of-the-week] user@host# set access-start 08:30 user#host# set access-end 16:30
You can also configure access to include both days and times. The following example
configures user access for the operator-day-shift
login class on
Monday, Wednesday, and Friday from 8:30 AM through 4:30 PM:
[edit system login class operator-day-shift] user@host# set allowed-days [ monday wednesday friday ] user@host# set access-start 08:30 user@host# set access-end 16:30
Alternatively, you can specify the login start time and end time for the
operator-day-shift
login class by using the following format:
[edit system login class operator-day-shift] user@host# set allowed-days [ monday wednesday friday ] user@host# set access-start 08:30am user@host# set access-end 04:30pm
The access start and end times might span across 12:00 AM on a given day. In that
case, the user still has access until the next day, even if you do not explicitly
configure that day in the allowed-days
statement.
Configure the Timeout Value for Idle Login Sessions
An idle login session is one in which the CLI displays the operational mode or configuration mode prompt but there is no input from the keyboard. By default, a login session remains established until a user logs out of the device, even if that session is idle. To close idle sessions automatically, you must configure a time limit for each login class. If a session established by a user in that class remains idle for the configured time limit, the session automatically closes. Automatically closing idle login sessions helps to prevent malicious users from gaining access to the device and performing operations with an authorized user account.
You can configure an idle timeout only for user-defined classes. You cannot
configure this option for the system predefined classes: operator
,
read-only
, super-user
or
superuser
, and unauthorized
.
To define the timeout value for idle login sessions:
If you configure a timeout value, the CLI displays messages similar to the following when timing out an idle user. The CLI starts displaying these messages 5 minutes before disconnecting the user.
user@host> Session will be closed in 5 minutes if there is no activity. Warning: session will be closed in 1 minute if there is no activity Warning: session will be closed in 10 seconds if there is no activity Idle timeout exceeded: closing session
If you configure a timeout value, the session closes after the specified time elapses, except in the following cases:
-
The user is running the
ssh
ortelnet
command. -
The user is logged into the local UNIX shell.
-
The user is monitoring interfaces using the
monitor interface
or themonitor traffic
command.
Login Retry Options
You can configure login retry options on Juniper Network devices to protect the devices from malicious users. You can configure the following options:
-
The number of times a user can enter invalid login credentials before the system closes the connection.
-
Whether and for how long to lock a user account after the user reaches the threshold of failed authentication attempts.
Limiting the login attempts and locking the user account help to protect the device from malicious users attempting to access the system by guessing the password of an authorized user account. You can unlock the user account or define a time period for the user account to remain locked.
You configure login retry options at the [edit system login
retry-options]
hierarchy level. The
tries-before-disconnect
statement defines the threshold of failed
login attempts before the device disconnects the user. The device allows three
unsuccessful login attempts by default.
The lockout-period
statement instructs the device to lock the user
account for the specified amount of time if the user reaches the threshold of
unsuccessful login attempts. The lock prevents the user from performing activities that
require authentication, until the lockout time period has elapsed or a system
administrator manually clears the lock. Any existing locks are ignored when the user
attempts to log in from the local console.
To configure login retry options:
-
Configure the number of times a user can attempt to enter a password.
[edit system login retry-options] user@host# set tries-before-disconnect number
For example, to enable a user to enter a password four times before the device closes the connection:
[edit system login retry-options] user@host# set tries-before-disconnect 4
- Configure the number of minutes that the user account remains locked after a user
reaches the threshold of failed login attempts.
[edit system login retry-options] user@host# set lockout-period minutes
For example, to lock a user account for 120 minutes after a user reaches the threshold of failed login attempts:
[edit system login retry-options] user@host# set lockout-period 120
-
Commit the configuration.
[edit system login retry-options] user@host# commit
To clear the console during an administrator-initiated logout, include newline (\n)
characters when you configure the message
statement at the
[edit system login]
hierarchy level. To completely clear the
console, the administrator can enter 50 or more \n characters in the message string.
For example:
user@host# set system login message "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n Welcome to Junos!!!"
Limit the Number of User Login Attempts for SSH and Telnet Sessions
You can limit the number of times a user can attempt to enter a password while logging in to a device through SSH or Telnet. The device terminates the connection if a user fails to log in after the number of specified attempts. You can also specify a delay, in seconds, before a user can try to enter a password after a failed attempt. In addition, you can specify the threshold for the number of failed attempts before the user experiences a delay in being able to enter a password again.
To specify the number of times a user can attempt to enter a password while logging
in, include the retry-options
statement at the [edit system
login]
hierarchy level:
[edit system login] retry-options { tries-before-disconnect number; backoff-threshold number; backoff-factor seconds; lockout-period minutes; maximum-time seconds minimum-time seconds; }
You can configure the following options:
-
tries-before-disconnect
—Maximum number of times a user can enter a password when logging in to the device through SSH or Telnet. The connection closes if a user fails to log in after the number specified. The range is from 1 through 10, and the default is 3. -
backoff-threshold
—Threshold for the number of failed login attempts before the user experiences a delay in being able to enter a password again. The range is from 1 through 3, and the default is 2. Use thebackoff-factor
option to specify the length of the delay. -
backoff-factor
—Length of time, in seconds, that the user must wait after a failed login attempt above thebackoff-threshold
. The delay increases by the specified value for each subsequent attempt after thebackoff-threshold
value. The range is from 5 through 10, and the default is 5 seconds. -
lockout-period
—Length of time, in minutes, that a user account is locked after reaching thetries-before-disconnect
threshold. The range is 1 through 43,200 minutes. -
maximum-time seconds
—Maximum length of time, in seconds, that the connection remains open for the user to enter a username and password to log in. If the user remains idle and does not enter a username and password within the configuredmaximum-time
, the connection closes. The range is from 20 through 300 seconds, and the default is 120 seconds. -
minimum-time
—Minimum length of time, in seconds, that a connection remains open while a user is attempting to enter a correct password. The range is from 20 through 60, and the default is 20 seconds.
Limiting the number of SSH and Telnet login attempts per user is one of the most
effective methods of stopping brute force attacks from compromising your network
security. Brute force attackers execute a large number of login attempts in a short
period of time to illegitimately gain access to a private network. By configuring
the retry-options
statements, you can create an increasing delay
after each failed login attempt, eventually disconnecting any user who passes your
set threshold of login attempts.
To limit the login attempts when a user logs in through SSH or Telnet:
For the following configuration, the user experiences a delay of 5 seconds after the second attempt to enter a correct password fails. After each subsequent failed attempt, the delay increases by 5 seconds. After the fourth and final failed attempt to enter a correct password, the user experiences an additional 10-second delay. The connection closes after a total of 40 seconds.
[edit] system { login { retry-options { backoff-threshold 2; backoff-factor 5; minimum-time 40; tries-before-disconnect 4; } } }
Example: Configure Login Retry Options
This example shows how to configure login retry options to protect a device from malicious users.
Requirements
Before you begin, you should understand Limit the Number of User Login Attempts for SSH and Telnet Sessions.
No special configuration beyond device initialization is required before configuring this feature.
Overview
Malicious users sometimes try to log in to a secure device by guessing the password of an authorized user account. You can lock a user account after a certain number of failed authentication attempts. This precaution helps protect devices from malicious users.
You can configure the number of failed login attempts before the device locks the user account, and you can configure the amount of time that the account remains locked. You can also configure the amount of time the user must wait between failed login attempts.
This example includes the following settings:
-
backoff-factor
—Length of delay in seconds that the user must wait after each failed login attempt above thebackoff-threshold
. The delay increases by this value for each subsequent login attempt after the value specified in thebackoff-threshold
statement. -
backoff-threshold
—Threshold for the number of failed login attempts on the device before the user experiences a delay when attempting to reenter a password. When a user reaches the threshold of failed login attempts, the user experiences the delay set in thebackoff-factor
statement. After the delay, the user can make another login attempt. -
lockout-period
—Number of minutes that the user account is locked after the user reaches thetries-before-disconnect
threshold. The user must wait the configured number of minutes before they can log in to the device again. -
tries-before-disconnect
—Maximum number of times the user can enter a password to attempt to log in to the device through SSH or Telnet.
If you are locked out of the device, you can log in to the device's console port, which ignores any user locks. This provides a way for administrators to remove the user lock on their own user account.
This example sets the tries-before-disconnect
option to 3. As a
result, the user has three attempts to log in to the device. If the number of failed
login attempts is equal to the value specified in the
backoff-threshold
statement, the user must wait for the
backoff-threshold
multiplied by the
backoff-factor
interval, in seconds, to get the login prompt.
In this example, the user must wait 5 seconds after the first failed login attempt
and 10 seconds after the second failed login attempt to get the login prompt. The
device disconnects the user after the third failed attempt.
If the user does not successfully log in after three attempts, the user account is locked. The user cannot log in until 120 minutes have elapsed, unless a system administrator manually clears the lock during that time.
A system administrator can manually unlock an account by issuing the clear
system login lockout user <username>
command.
The show system login lockout
command displays which user accounts
are locked and when the lockout period begins and ends for each user.
Configuration
Procedure
CLI Quick Configuration
To quickly configure this example, copy the following commands, paste them
into a text file, remove any line breaks, change any details necessary to
match your network configuration, copy and paste the commands into the CLI
at the [edit]
hierarchy level, and then enter
commit
from configuration mode.
set system login retry-options backoff-factor 5 set system login retry-options backoff-threshold 1 set system login retry-options lockout-period 120 set system login retry-options tries-before-disconnect 3
Step-by-Step Procedure
To configure system retry-options:
-
Configure the backoff factor.
[edit] user@host# set system login retry-options backoff-factor 5
-
Configure the backoff threshold.
[edit] user@host# set system login retry-options backoff-threshold 1
-
Configure the number of minutes that the user account remains locked after a user reaches the threshold of failed login attempts.
[edit] user@host# set system login retry-options lockout-period 120
-
Configure the number of times a user can attempt to enter a password.
[edit] user@host# set system login retry-options tries-before-disconnect 3
Results
From configuration mode, confirm your configuration by entering the
show system login retry-options
command. If the output
does not display the intended configuration, repeat the configuration
instructions in this example to correct it.
[edit] user@host# show system login retry-options tries-before-disconnect 3; backoff-threshold 1; backoff-factor 5; lockout-period 120;
If you are done configuring the device, enter commit
from
configuration mode.
Verification
Display the Locked User Logins
Purpose
Verify that the login lockout configuration is enabled.
Action
Attempt three unsuccessful logins for a particular username. The device will
be locked for that username. Then log in to the device with a different
username. From operational mode, issue the show system login
lockout
command to view the locked accounts.
user@host> show system login lockout User Lockout start Lockout end jsmith 2021-08-17 16:27:28 PDT 2021-08-17 18:27:28 PDT
Meaning
After you perform three unsuccessful login attempts with a particular
username, the device is locked for that user for 120 minutes, as configured
in the example. You can verify that the device is locked for that user by
logging in to the device with a different username and entering the
show system login lockout
command.