在CentOS系统中,SFTP(SSH File Transfer Protocol)的会话超时时间可以通过修改SSH服务器的配置文件来实现。以下是具体步骤:
/etc/ssh/sshd_config 文件备份原始配置文件:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
编辑配置文件:
sudo vi /etc/ssh/sshd_config
找到或添加以下配置项:
ClientAliveInterval 300
ClientAliveCountMax 0
ClientAliveInterval:设置服务器向客户端发送空闲数据包的时间间隔(以秒为单位)。默认值通常是0,表示不发送。ClientAliveCountMax:设置服务器在断开连接前允许客户端无响应的最大次数。设置为0表示不自动断开连接。例如,如果你想设置会话超时时间为30分钟(1800秒),可以这样设置:
ClientAliveInterval 1800
ClientAliveCountMax 0
保存并退出编辑器:
Esc 键,然后输入 :wq 并按 Enter 键。重启SSH服务:
sudo systemctl restart sshd
sshd_config.d 目录如果你不想直接修改 /etc/ssh/sshd_config 文件,可以使用 sshd_config.d 目录来添加配置。
创建一个新的配置文件:
sudo vi /etc/ssh/sshd_config.d/sftp_timeout.conf
添加配置项:
ClientAliveInterval 1800
ClientAliveCountMax 0
保存并退出编辑器。
重启SSH服务:
sudo systemctl restart sshd
你可以通过以下命令来验证配置是否生效:
sudo systemctl status sshd
查看输出中的 ClientAliveInterval 和 ClientAliveCountMax 是否与你设置的值一致。
通过以上步骤,你就可以成功设置CentOS系统中SFTP会话的超时时间。