User-Profile-Image
hankin
  • 5
  • 首页
  • 分类
    • Windows
    • Web
    • VoIP
    • Virtualization
    • Trading
    • Smart Home
    • SEO
    • Security
    • Python
    • Program
    • PHP
    • OSX
    • OS
    • OpenSource
    • Nginx
    • MySQL
    • Mood
    • Linux
    • Life
    • Injection
    • Hosting
    • Finance
    • Exploits
    • CDN
  • 页面
    • About
  • 友链
    • 维酷科技
    • Tesra超算网络
Help?

Please contact us on our email for need any support

Support
  • 首页
    首页   ›   OS   ›   OSX   ›   正文
OSX

Mac环境下解决SSH超时断开

2015-05-27 13:28:20
2622  0 0

方法一

配置服务器,修改/etc/ssh/sshd_config配置文件,找到ClientAliveCountMax(单位为分钟)修改你想要的值,执行service sshd reload;

方法二

配置服务器,修改/etc/profile配置文件

# vi /etc/profile

增加:TMOUT=1800
这样30分钟没操作就自动LOGOUT(SSH超时断开)。

方法三

配置客户端,找到所在用户的.ssh目录,如root用户该目录在:

/root/.ssh/
在该目录创建config文件(若没有,直接创建一个config)

vi /root/.ssh/config

加入下面一句:
ServerAliveInterval 60
保存退出,重新开启root用户的shell,则再ssh远程服务器的时候,不会因为长时间操作断开。应该是加入这句之后,ssh客户端会每隔一段时间自动与ssh服务器通信一次,所以长时间操作不会断开。

方法四

利用expect 模拟键盘动作,在闲置时间之内模拟地给个键盘响应,将下列代码保存为xxx,然后用expect执行

#!/usr/bin/expect  
set timeout 60  
spawn ssh user@host   
      interact {          
            timeout 300 {send "\x20"}  
      } 
expect xxx

接着按提示输入密码就可以了,这样每隔300秒就会自动打一个空格(\x20),具体的时间间隔可以根据具体情况设置。

ProdigYu
180文章 77评论 4点赞 553966浏览
随机文章
群晖Docker服务卡死通过命令重启
3年前
SFTP命令下载整个目录
9年前
远程桌面管理器V2.2
11年前
VMwareServer限速设置
15年前
6.28百度大更新
13年前
Tags
Apache CentOS CMD DDOS Debian DNS Docker FastCGI Google IIS IP iptables Linux Mac MySQL Nginx Opensource PHP Python Skill SSH Ubuntu Vim VMware VPN web.py Windows 删除 命令 命令提示符 安装 开源 技巧 插件 漏洞 百度 系统 组件 终端 缓存 网络电话 脚本 自建 详解 错误
Meta
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright © 2025
主页
页面
  • About
博主
ProdigYu 管理员
Something about myself
180 文章 77 评论 553966 浏览
测试
测试