iTerm 2 如何让 session 一直不掉线

2016-11-05 22:45:31 +08:00
 yangpai

iTerm 2 如何让 session 一直不掉线呢, win 下的 xshell 如果不主动关闭就一直有效的,而 iTerm 2 如果一会不操作, 就会失效, 然后就不能再操作了。

10729 次点击
所在节点    Apple
20 条回复
kungfuchicken
2016-11-05 23:38:01 +08:00
编辑或创建~/.ssh/config
增加

Host *
ServerAliveInterval 300
ServerAliveCountMax 3

300 是发给服务端心跳的间隔,单位是秒,根据你自己的服务器情况设置
3 是最多发送的次数,如果想一直保持连接,本项目可以不写
wwwjfy
2016-11-06 00:14:42 +08:00
mosh
yangxin0
2016-11-06 00:21:38 +08:00
tmux
awanabe
2016-11-06 00:25:06 +08:00
在 profile->session 里面倒数第二个 when Idle , send ASCII code every seconds
就不会断线了

p.s 2,3 楼会不会好好回答问题
introom
2016-11-06 08:13:44 +08:00
mosh 加 tmux 是正解。
tinybaby365
2016-11-06 08:15:19 +08:00
@wwwjfy 这是 UDP 的,内网使用很赞!外网怕安全问题,不敢用。
livc
2016-11-06 08:19:38 +08:00
@wwwjfy 不能 scroll back 蛋疼啊
livc
2016-11-06 08:20:44 +08:00
profile 里可以设置隔多久发一个 ASCII 码什么的
cxbig
2016-11-06 08:51:01 +08:00
远程 ssh 还是在 remote 上跑 tmux 比较好,断了连回去东西都还在
很多极端情况延长心跳间隔没啥作用
20015jjw
2016-11-06 09:46:59 +08:00
@cxbig +1 正解
wwwjfy
2016-11-06 10:20:09 +08:00
@livc 确实,只能加 tmux

@jiangfengbing UDP 和安全有什么关系,只是传输协议

Q: What is Mosh's security track record so far?
Mosh 1.0 was released in March 2012. As of the release of Mosh 1.2.6 in August 2016, as far as the developers are aware:

- In the last four years, no security vulnerabilities of any kind (major or minor) have been reported in Mosh.
- No major security vulnerabilities have ever been reported in Mosh. We define major security vulnerabilities to include privilege escalation, remote code execution, denial-of-service by a third party, etc.
- Two denial-of-service issues were discovered and fixed in releases in 2012. One issue allowed a mosh-server to cause the mosh-client to spend excess CPU (CVE-2012-2385, fixed in Mosh 1.2.1, released May 2012). Another issue allowed the server host to cause the mosh-client to send UDP datagrams to an incorrect address, foiling its attempt to connect (fixed in Mosh 1.2.2, released July 2012).
hst001
2016-11-06 13:20:06 +08:00
我的 iTerm 2 好像没出现过这问题,也没配置过
ETiV
2016-11-06 14:26:41 +08:00
我倒是想知道如何强制开启 session restore

cmd q 退出是不能 restore 的
但是系统重启的退出,再开机是有的
tinybaby365
2016-11-06 14:59:11 +08:00
@wwwjfy 每个连接除了默认的 22 外都需要一个额外的端口开放,动态分配的端口范围是 60000-61000 。有多少公司的运维愿意这么干。
wwwjfy
2016-11-06 15:13:25 +08:00
@jiangfengbing
- 这是事实
- 和 UDP 没关系
- 运维不愿意没办法,但实际上 TCP 22 和 UDP 60000 在安全性上没什么差别, mosh 也可以指定某一个端口。当然多一个端口多一点风险,就看方便性和安全性的取舍了。
2owe
2016-11-07 00:15:34 +08:00
用阿里云确实碰到过频繁掉线的问题,后来用 ssh 方式加 ServerAliveInterval 选项,好了一些,偶尔掉线。

再后来在服务器用了 tmux ,就不怕掉线了。

再后来发现了 mosh ,随用随连。

再后来,学会配 ssh config 和 ssh public-key ,登录更方便了。

再后来,在 iterm 里设置了快捷键,输入登录服务器那一串,登录服务器变成了按三个键。

再后来,我写了篇博客: http://blog.hit1024.com/post/2016-10-30
yangpai
2016-11-07 10:01:06 +08:00
@2owe 666
redkei
2016-11-07 18:06:24 +08:00
@2owe
rubygo
2020-12-08 14:51:51 +08:00
@2owe 再后来
2020 年 12 月
你的网站无法访问
2owe
2020-12-08 15:53:57 +08:00
@shengminjie https://hit1024.com/post/2016-10-30
2333,这篇感觉写得还行,欢迎拍砖

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/318371

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX