ssh连接超时的解决办法

ssh连接超时的解决办法

再来看,设置ssh超时时间的方法。
修改自己 root 目录下的.bash_profile文件,加上
export TMOUT=1000000 (以秒为单位)
然后运行:

source .bash_profile
在/etc/ssh/sshd_config中加入:
ClientAliveInterval=60
每一分钟,sshd都和ssh client打个招呼,检测它是否存在,不存时即断开连接。

注意:设置完成后,要退出ssh远程连接,再次登录后才可以生效。因为要再读取一次./bash_profile。
为了方便,将设置写成了如下脚本:

echo export TMOUT=1000000 >> /root/.bash_profile
cat /root/.bash_profile
source .bash_profile
cp /etc/ssh/sshd_config /etc/ssh/sshd_config_bak
echo ClientAliveInterval=60 >> /etc/ssh/sshd_config
service sshd restart
cat /etc/ssh/sshd_config
service sshd restart
exit
总结:

ClientAliveInterval(/etc/ssh/sshd_config)、环境变量TMOUT(在/etc/profile或.bash_profile中设置)以及putty的"Seconds between keepalives“这些方法中,经
检测,只有TMOUT可以控制ssh连?在空闲时间超时,自动断开连接的时间,数字单位为“秒”。
在设置了TMOUT后(非0),另外两个变量则不起作用的。

更多信息:
了解更多ssh_timeout_in_linux
如何增加ssh timeout时间 increase linux ssh connection timeout quick guide
setup ssh keys to login linux without password

解决 ssh 连接 git 超时问题,可参考以下方法: 1. **测试 SSH 连接**:在 Git Bash 终端使用 `ssh -T git@github.com` 命令测试与 GitHub 的 SSH 连接。若出现 `ssh: connect to host github.com port 22: Connection timed out` 提示,表明 22 端口连接超时 [^1]。 2. **使用 SSH over HTTPS port**:将 SSH 配置文件修改为如下内容: ```plaintext Host github.com HostName ssh.github.com User git Port 443 ``` 若该方法不顺利,连接仍然超时,可尝试下一种方法 [^2]。 3. **结合两种方案修改配置文件**:把上述两个方案修改的部分进行整合,将配置文件修改为: ```plaintext Host github.com ProxyCommand "C:\Program Files\Git\mingw64\bin\connect.exe" -S 127.0.0.1:7890 %h %p HostName ssh.github.com User git Port 443 ``` 如果此方法也不顺利,可参考关于 SSH - GitHub 文档或在相关视频下评论讨论 [^2]。 4. **修改 SSH 配置文件并验证连接**: - **修改配置文件**:打开或创建 SSH 配置文件(Linux/macOS 为 `~/.ssh/config`,Windows 为 `C:\Users\<你的用户名>\.ssh\config`),添加以下内容: ```plaintext Host github.com Hostname ssh.github.com User git Port 443 PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa # 如果密钥是其他名称或路径,请修改此处,例如 id_ed25519 ``` 对于 Windows 用户,`IdentityFile` 路径可能需要写全,例如 `IdentityFile C:\Users\<你的用户名>\.ssh\id_rsa` [^3]。 - **验证连接**:保存配置文件后,打开终端(Terminal/Git Bash),运行 `ssh -T git@github.com` 命令测试连接。若配置成功,会看到类似 `Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.` 的成功验证消息 [^3]。 - **再次克隆**:再次运行 `git clone` 命令查看问题是否解决 [^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值