更新:从 16.1 开始,这可以通过以下配置实现:
set system login idle-timeout n
n分钟数在哪里。
https://www.juniper.net/documentation/us/en/software/junos/network-mgmt/topics/ref/statement/idle-timeout--edit-system-login.html
对于 16.1 之前的代码版本,以下答案仍然有效。
不幸的是,无法直接从 CLI 为 root 设置空闲超时。
我写了一个事件脚本,可以满足您的需求。
基本上,它每 5 分钟检查一次:
- 如果 root 通过控制台登录(通过“show system users”的“FROM”部分中的“-”验证)
- 如果 root 已登录,它是否空闲 15 分钟或更长时间(以秒为单位检查,因此为 900 秒)。
- 如果满足所有这些要求,请发出“请求系统注销终端 $TERM”(使用脚本提取的信息中存在的任何终端)。
拉取内容的非 XML 版本:
jhead@VPN-EP1> show system users
4:02PM up 2:56, 2 users, load averages: 0.07, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE WHAT
root v0 - 3:55PM 6 cli
jhead p0 172.16.67.1 1:09PM - -cli (cli)
您可以通过发出以下命令来更详细地了解脚本解析的信息:
show system users | display xml
脚本本身:(文件名:terminate-idle-root.slax)
/*
* Author : Jordan Head
* Company : Juniper Networks
* Version : 1.0
* Last Modified : December 13, 2015
* Platform : all
*
* Description : This event script periodically checks for root user sessions logged in
* via out-of-band console that have been idle for 15 minutes or more, and terminates the session.
*
*/
version 1.0;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
import "../import/junos.xsl";
var $event-definition = {
<event-options> {
<generate-event> {
<name> "5-minute-delay";
<time-interval> "300";
}
<policy> {
<name> "terminate-idle-root";
<events> "5-minute-delay";
<then> {
<event-script> {
<name> "terminate-idle-root.slax";
}
}
}
}
}
match / {
<op-script-results> {
var $root_user = "root";
var $idle_time = "900";
var $from = "-";
var $show-system-users-output = <get-system-users-information>;
var $show-system-users = jcs:invoke($show-system-users-output);
for-each ($show-system-users/uptime-information/user-table/user-entry) {
var $user_check = ./user;
var $idle_time_check = ./idle-time/@junos:seconds;
var $from_check = ./from;
var $tty = ./tty;
if ($user_check == $root_user && $idle_time_check >= $idle_time && $from_check == $from) {
var $terminate_root_console = <command> "request system logout terminal " _ $tty;
expr jcs:invoke($terminate_root_console);
}
}
}
}
应用脚本:
如果提交成功,则意味着脚本的语法是有效的。
jhead@VPN-EP1> configure exclusive
warning: uncommitted changes will be discarded on exit
Entering configuration mode
[edit]
jhead@VPN-EP1# set event-options event-script file terminate-idle-root.slax
[edit]
jhead@VPN-EP1# commit and-quit
commit complete
Exiting configuration mode
希望这会有所帮助,如果有任何不清楚的地方,请随时发表评论,我很乐意更新我的答案。
最后一点:@bob 是对的,应该可以。我刚刚看到保持连接的控制台设备,但允许访问盒子本身,因此它不会终止。如果您正在进行典型设置,他的解决方案将起作用 - 但我已经看到了它不会的实现。
调整 root Shell 的超时时间:
只是想再添加一件有人引起我注意的快速事情。
如果您担心 root 用户 shell 会话(不是 CLI)上的空闲超时,您可以跳转到一个 shell 并设置:
set autologout=X ## Where X is the number of minutes of idle time before session is terminated.
您添加/编辑文件 /etc/csh.login