最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

linux - VSCode SSH Connection to Root User Disconnects After 20 Seconds and Disables SSH - Stack Overflow

programmeradmin2浏览0评论

I'm using VSCode Remote-SSH to connect to my Ubuntu server as the root user. The connection works initially, and I can run commands, but after about 20 seconds, it suddenly disconnects. After this happens, SSH becomes completely disabled, and I can no longer reconnect until I restart the server.

Here is what I have already checked and configured:

  1. SSH Configuration (/etc/ssh/sshd_config)

    PermitRootLogin yes

    PubkeyAuthentication yes

I can log in as root using VSCode. Commands execute normally before the disconnect. After ~20 seconds, SSH disconnects, and I cannot reconnect. Restarting the server allows me to reconnect again.

I have not installed any additional firewall software (no ufw or iptables rules blocking SSH).

I reviewed the logs, and it seems there is no record of using VSCode for SSH connections, and I did not use VSCode during the time the logs were recorded. However, some articles mention that large memory consumption by VSCode extensions can cause server crashes, but my server hasn't crashed — it's just that I can't reconnect.

I believe my configuration is correct, as I can connect briefly after restarting the server, but the connection drops soon after.

Does anyone have any ideas on why I am experiencing this issue or how I can resolve it? Any help is greatly appreciated!

this is the log:

Last login: Mon Feb 10 15:14:36 2025 from 100.104.192.181
root@test:~# systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2025-02-10 09:30:58 CST; 5h 43min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 1000 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
   Main PID: 1033 (sshd)
      Tasks: 1 (limit: 1910)
     Memory: 11.6M
        CPU: 1.102s
     CGroup: /system.slice/ssh.service
             └─1033 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Feb 10 14:07:39 test sshd[10203]: Connection closed by 45.79.181.223 port 39154 [preauth]
Feb 10 14:07:41 test sshd[10205]: Connection closed by 45.79.181.223 port 39168 [preauth]
Feb 10 15:14:20 test sshd[10286]: error: Received disconnect from 100.104.192.167 port 45714:10: [preauth]
Feb 10 15:14:20 test sshd[10286]: Disconnected from authenticating user root 100.104.192.167 port 45714 [preauth]
Feb 10 15:14:35 test sshd[10288]: Accepted publickey for root from 100.104.192.152 port 47699 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:14:35 test sshd[10288]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Feb 10 15:14:36 test sshd[10307]: Accepted publickey for root from 100.104.192.181 port 33229 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:14:36 test sshd[10307]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Feb 10 15:14:37 test sshd[10440]: Accepted publickey for root from 100.104.192.181 port 33239 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:14:37 test sshd[10440]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)


root@test:~# systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2025-02-10 09:30:58 CST; 5h 56min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 1000 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
   Main PID: 1033 (sshd)
      Tasks: 1 (limit: 1910)
     Memory: 9.3M
        CPU: 1.483s
     CGroup: /system.slice/ssh.service
             └─1033 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Feb 10 15:27:20 test sshd[11131]: pam_unix(sshd:session): session closed for user root
Feb 10 15:27:22 test sshd[11179]: Accepted publickey for root from 100.104.192.181 port 41149 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:27:22 test sshd[11179]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Feb 10 15:27:23 test sshd[11179]: pam_unix(sshd:session): session closed for user root
Feb 10 15:27:23 test sshd[11227]: Accepted publickey for root from 100.104.192.181 port 41161 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:27:23 test sshd[11227]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Feb 10 15:27:24 test sshd[11227]: pam_unix(sshd:session): session closed for user root
Feb 10 15:27:25 test sshd[11275]: Accepted publickey for root from 100.104.192.181 port 41172 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:27:25 test sshd[11275]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Feb 10 15:27:25 test sshd[11275]: pam_unix(sshd:session): session closed for user root

I'm using VSCode Remote-SSH to connect to my Ubuntu server as the root user. The connection works initially, and I can run commands, but after about 20 seconds, it suddenly disconnects. After this happens, SSH becomes completely disabled, and I can no longer reconnect until I restart the server.

Here is what I have already checked and configured:

  1. SSH Configuration (/etc/ssh/sshd_config)

    PermitRootLogin yes

    PubkeyAuthentication yes

I can log in as root using VSCode. Commands execute normally before the disconnect. After ~20 seconds, SSH disconnects, and I cannot reconnect. Restarting the server allows me to reconnect again.

I have not installed any additional firewall software (no ufw or iptables rules blocking SSH).

I reviewed the logs, and it seems there is no record of using VSCode for SSH connections, and I did not use VSCode during the time the logs were recorded. However, some articles mention that large memory consumption by VSCode extensions can cause server crashes, but my server hasn't crashed — it's just that I can't reconnect.

I believe my configuration is correct, as I can connect briefly after restarting the server, but the connection drops soon after.

Does anyone have any ideas on why I am experiencing this issue or how I can resolve it? Any help is greatly appreciated!

this is the log:

Last login: Mon Feb 10 15:14:36 2025 from 100.104.192.181
root@test:~# systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2025-02-10 09:30:58 CST; 5h 43min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 1000 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
   Main PID: 1033 (sshd)
      Tasks: 1 (limit: 1910)
     Memory: 11.6M
        CPU: 1.102s
     CGroup: /system.slice/ssh.service
             └─1033 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Feb 10 14:07:39 test sshd[10203]: Connection closed by 45.79.181.223 port 39154 [preauth]
Feb 10 14:07:41 test sshd[10205]: Connection closed by 45.79.181.223 port 39168 [preauth]
Feb 10 15:14:20 test sshd[10286]: error: Received disconnect from 100.104.192.167 port 45714:10: [preauth]
Feb 10 15:14:20 test sshd[10286]: Disconnected from authenticating user root 100.104.192.167 port 45714 [preauth]
Feb 10 15:14:35 test sshd[10288]: Accepted publickey for root from 100.104.192.152 port 47699 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:14:35 test sshd[10288]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Feb 10 15:14:36 test sshd[10307]: Accepted publickey for root from 100.104.192.181 port 33229 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:14:36 test sshd[10307]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Feb 10 15:14:37 test sshd[10440]: Accepted publickey for root from 100.104.192.181 port 33239 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:14:37 test sshd[10440]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)


root@test:~# systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2025-02-10 09:30:58 CST; 5h 56min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 1000 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
   Main PID: 1033 (sshd)
      Tasks: 1 (limit: 1910)
     Memory: 9.3M
        CPU: 1.483s
     CGroup: /system.slice/ssh.service
             └─1033 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Feb 10 15:27:20 test sshd[11131]: pam_unix(sshd:session): session closed for user root
Feb 10 15:27:22 test sshd[11179]: Accepted publickey for root from 100.104.192.181 port 41149 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:27:22 test sshd[11179]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Feb 10 15:27:23 test sshd[11179]: pam_unix(sshd:session): session closed for user root
Feb 10 15:27:23 test sshd[11227]: Accepted publickey for root from 100.104.192.181 port 41161 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:27:23 test sshd[11227]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Feb 10 15:27:24 test sshd[11227]: pam_unix(sshd:session): session closed for user root
Feb 10 15:27:25 test sshd[11275]: Accepted publickey for root from 100.104.192.181 port 41172 ssh2: RSA SHA256:kjEMuGZGOCGmGJ9DCIK3OPVIammPbfBNMb3NqviL1v4
Feb 10 15:27:25 test sshd[11275]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Feb 10 15:27:25 test sshd[11275]: pam_unix(sshd:session): session closed for user root
Share Improve this question edited 8 hours ago 459zyt asked 15 hours ago 459zyt459zyt 651 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

there is not much that I can help with your current provided information. The problem that you are experiencing could have multiple of root causes.

First thing first that you can do is during Troubleshooting is to always check the log of find out what's happening. For example, you can try to check the SSH service status by using systemctl status sshd command or you can use journalctl to check the log generated by the service to find out what's happening.

Here's an article that I found online that can help you to start to troubleshoot your SSH issue: https://docs.digitalocean.com/support/how-to-troubleshoot-ssh-connectivity-issues/

Feel free to edit your question and hit me up when you have found something more from the logs and I'll help you.

Cheers!

发布评论

评论列表(0)

  1. 暂无评论