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
    • 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
433  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
164文章 12评论 2点赞 93493浏览
随机文章
Windows下对路由表简单操作
7年前
免费开源的WHMCS支付宝插件
11年前
Debian下Python错误No module named MySQLdb
5年前
最近倒霉事情比较多
10年前
25个实用的SSH命令
7年前
Tags
Apache CentOS CMD DDOS Debian DNS FastCGI Google IIS IP iptables Linux Mac MySQL Nginx Opensource PHP Python Skill Spawn-FCGI SSH Ubuntu Vim VMware VPN web.py Windows 删除 命令 命令提示符 安装 开源 技巧 插件 漏洞 百度 系统 组件 终端 缓存 网络电话 脚本 自建 详解 错误
Meta
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright © 2021
Designed by hankin
主页
页面
  • About
博主
ProdigYu 管理员
Something about myself
164 文章 12 评论 93493 浏览
测试
测试