ubuntu能ping通却ssh不上(connect to localhost port 22: Connection refused)解决办法

本文介绍了当遇到SSH连接被拒绝的情况时如何排查及解决的方法。主要原因是Ubuntu未安装openssh-server,通过使用命令行工具检查并安装openssh-server来解决连接问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 问题描述:

ssh 192.168.144.130
ssh: connect to host 192.168.144.130 port 22: Connection refused
这里写图片描述

2. 原因

因为Ubuntu默认没有安装openssh-server

  • 检查是否安装:
$ ps -e|grep ssh

如果输出没有或者只有一个ssh-agent就说没没安装.

这里写图片描述

3.解决办法

  • 安装openssh-server
$ sudo apt-get install openssh-server
  • 检查是否安装成功
$ ssh localhost
//或者用
$ ps -e|grep ssh
  • 如果要输密码就说明成功
    这里写图片描述

  • 如有其他问题欢迎留言探讨!!

[16:00:08.942] Log Level: 2 [16:00:08.952] SSH Resolver called for "ssh-remote+ubuntu", attempt 1 [16:00:08.953] "remote.SSH.useLocalServer": false [16:00:08.953] "remote.SSH.useExecServer": true [16:00:08.953] "remote.SSH.showLoginTerminal": true [16:00:08.953] "remote.SSH.remotePlatform": {} [16:00:08.953] "remote.SSH.path": undefined [16:00:08.953] "remote.SSH.configFile": undefined [16:00:08.953] "remote.SSH.useFlock": true [16:00:08.953] "remote.SSH.lockfilesInTmp": false [16:00:08.953] "remote.SSH.localServerDownload": auto [16:00:08.953] "remote.SSH.remoteServerListenOnSocket": false [16:00:08.953] "remote.SSH.showLoginTerminal": true [16:00:08.953] "remote.SSH.defaultExtensions": [] [16:00:08.953] "remote.SSH.loglevel": 2 [16:00:08.953] "remote.SSH.enableDynamicForwarding": true [16:00:08.953] "remote.SSH.enableRemoteCommand": false [16:00:08.953] "remote.SSH.serverPickPortsFromRange": {} [16:00:08.953] "remote.SSH.serverInstallPath": {} [16:00:08.953] "remote.SSH.permitPtyAllocation": false [16:00:08.953] "remote.SSH.preferredLocalPortRange: undefined [16:00:08.953] "remote.SSH.useCurlAndWgetConfigurationFiles: false [16:00:08.958] SSH Resolver called for host: ubuntu [16:00:08.958] Setting up SSH remote "ubuntu" [16:00:08.967] VS Code version: 1.95.3 [16:00:08.967] Remote-SSH version: remote-ssh@0.115.1 [16:00:08.967] win32 x64 [16:00:08.968] Using commit id "f1a4fb101478ce6ec82fe9627c43efbf9e98c813" and quality "stable" for server [16:00:08.971] Script variables: { "InstallExitCode.24": "AlreadyInProgress", "InstallExitCode.25": "ServerDownloadFailed", "InstallExitCode.26": "NoDownloaderAvailable", "InstallExitCode.27": "UnsupportedArch", "InstallExitCode.28": "StatusCheckFailed", "InstallExitCode.29": "NeedInsidersArch", "InstallExitCode.30": "NoDownloaderAvailableForStatusCheck", "InstallExitCode.31": "ServerTransferFailed", "InstallExitCode.32": "ServerFailedToStart", "InstallExitCode.33": "NeedInsidersWindows", "InstallExitCode.34": "CreateInstallDirFailed", "InstallExitCode.35": "UnsupportedPlatform", "InstallExitCode.36": "ServerTerminatedCVE20201416", "InstallExitCode.37": "UnpackFailed", "InstallExitCode.38": "ChangeDirFailed", "InstallExitCode.AlreadyInProgress": "24", "InstallExitCode.ServerDownloadFailed": "25", "InstallExitCode.NoDownloaderAvailable": "26", "InstallExitCode.NoDownloaderAvailableForStatusCheck": "30", "InstallExitCode.UnsupportedArch": "27", "InstallExitCode.StatusCheckFailed": "28", "InstallExitCode.NeedInsidersArch": "29", "InstallExitCode.ServerTransferFailed": "31", "InstallExitCode.ServerFailedToStart": "32", "InstallExitCode.NeedInsidersWindows": "33", "InstallExitCode.CreateInstallDirFailed": "34", "InstallExitCode.UnsupportedPlatform": "35", "InstallExitCode.ServerTerminatedCVE20201416": "36", "InstallExitCode.UnpackFailed": "37", "InstallExitCode.ChangeDirFailed": "38", "InstallUnpackCode.Success": "success", "InstallUnpackCode.Error": "error", "InstallUnpackCode.MissingFiles": "missingFiles", "uuid": "be116060ecd4", "startMarker": "be116060ecd4: running", "commitId": "f1a4fb101478ce6ec82fe9627c43efbf9e98c813", "quality": "stable", "token": "111a111a-a111-1111-111a-111aaa11a11a", "vscodeAgentFolder": "$HOME/.vscode-server", "allowClientDownload": "1", "forceClientDownload": "0", "cliNameInArchive": "code", "ignoreWgetConfigFlag": " --no-config ", "ignoreCurlConfigFlag": " --disable ", "wgetTriesSegment": "--tries=1", "listenArgs": "--on-host=127.0.0.1 --on-port", "getDownloadServerStartTrigger": "be116060ecd4:trigger_server_download", "getDownloadServerEndTrigger": "be116060ecd4:trigger_server_download_end", "getProgressDownloading": "be116060ecd4%%1%%", "getProgressInstalling": "be116060ecd4%%2%%" } [16:00:08.973] Install and start server if needed [16:00:10.216] Checking ssh with "D:\xuniji\bin\ssh.exe -V" [16:00:10.218] Got error from ssh: spawn D:\xuniji\bin\ssh.exe ENOENT [16:00:10.218] Checking ssh with "C:\WINDOWS\system32\ssh.exe -V" [16:00:10.218] Got error from ssh: spawn C:\WINDOWS\system32\ssh.exe ENOENT [16:00:10.218] Checking ssh with "C:\WINDOWS\ssh.exe -V" [16:00:10.219] Got error from ssh: spawn C:\WINDOWS\ssh.exe ENOENT [16:00:10.219] Checking ssh with "C:\WINDOWS\System32\Wbem\ssh.exe -V" [16:00:10.220] Got error from ssh: spawn C:\WINDOWS\System32\Wbem\ssh.exe ENOENT [16:00:10.220] Checking ssh with "C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe -V" [16:00:10.220] Got error from ssh: spawn C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe ENOENT [16:00:10.220] Checking ssh with "C:\WINDOWS\System32\OpenSSH\ssh.exe -V" [16:00:10.255] > OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2 [16:00:10.259] Running script with connection command: "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 54906 ubuntu sh [16:00:10.260] Generated SSH command: 'type "C:\Users\admin\AppData\Local\Temp\vscode-linux-multi-line-command-ubuntu-92598382.sh" | "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 54906 ubuntu sh' [16:00:10.261] Using connect timeout of 17 seconds [16:00:10.261] Terminal shell path: C:\WINDOWS\System32\cmd.exe [16:00:10.453] > [?9001h[?1004h > > > > > > > > > > > > ]0;C:\WINDOWS\System32\cmd.exe [16:00:10.453] Got some output, clearing connection timeout [16:00:21.848] > ssh: connect to host ubuntu port 22: Connection refused [16:00:21.862] > 过程试图写入的管道存在。 [16:00:23.128] "install" terminal command done [16:00:23.128] Install terminal quit with output: 过程试图写入的管道存在。 [16:00:23.128] Received install output: 过程试图写入的管道存在。 [16:00:23.129] Failed to parse remote port from server output [16:00:23.130] Resolver error: Error: at v.Create (c:\Users\admin\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.1\out\extension.js:2:493431) at t.handleInstallOutput (c:\Users\admin\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.1\out\extension.js:2:490753) at t.tryInstall (c:\Users\admin\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.1\out\extension.js:2:608797) at async c:\Users\admin\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.1\out\extension.js:2:568008 at async t.withShowDetailsEvent (c:\Users\admin\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.1\out\extension.js:2:571256) at async P (c:\Users\admin\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.1\out\extension.js:2:564794) at async t.resolve (c:\Users\admin\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.1\out\extension.js:2:568667) at async c:\Users\admin\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.1\out\extension.js:2:839059 [16:00:23.133] ------分析一下错误原因
07-31
[17:19:01.210] Log Level: 2 [17:19:01.220] SSH Resolver called for "ssh-remote+127.0.1.1", attempt 1 [17:19:01.223] remote.SSH.useLocalServer = true [17:19:01.223] remote.SSH.useExecServer = true [17:19:01.223] remote.SSH.bindHost = {} [17:19:01.223] remote.SSH.path = [17:19:01.223] remote.SSH.configFile = [17:19:01.223] remote.SSH.useFlock = true [17:19:01.223] remote.SSH.lockfilesInTmp = false [17:19:01.223] remote.SSH.localServerDownload = auto [17:19:01.224] remote.SSH.remoteServerListenOnSocket = false [17:19:01.224] remote.SSH.defaultExtensions = [] [17:19:01.224] remote.SSH.defaultExtensionsIfInstalledLocally = [] [17:19:01.224] remote.SSH.loglevel = 2 [17:19:01.224] remote.SSH.enableDynamicForwarding = true [17:19:01.224] remote.SSH.enableRemoteCommand = false [17:19:01.224] remote.SSH.serverPickPortsFromRange = {} [17:19:01.224] remote.SSH.serverInstallPath = {} [17:19:01.224] remote.SSH.permitPtyAllocation = false [17:19:01.224] remote.SSH.preferredLocalPortRange = undefined [17:19:01.224] remote.SSH.useCurlAndWgetConfigurationFiles = false [17:19:01.224] remote.SSH.experimental.chat = true [17:19:01.224] remote.SSH.experimental.enhancedSessionLogs = true [17:19:01.224] remote.SSH.httpProxy = {"*":""} [17:19:01.224] remote.SSH.httpsProxy = {"*":""} [17:19:01.231] VS Code version: 1.102.3 [17:19:01.231] Remote-SSH version: remote-ssh@0.120.0 [17:19:01.231] linux x64 [17:19:01.233] SSH Resolver called for host: 127.0.1.1 [17:19:01.233] Setting up SSH remote "127.0.1.1" [17:19:01.236] Acquiring local install lock: /tmp/vscode-remote-ssh-23c6a5dd-install.lock [17:19:01.237] Looking for existing server data file at /home/ubuntuworld/.config/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-23c6a5dd-488a1f239235055e34e673291fb8d8c810886f81-0.120.0-es/data.json [17:19:01.237] No existing data file [17:19:01.238] Using commit id "488a1f239235055e34e673291fb8d8c810886f81" and quality "stable" for server [17:19:01.238] Extensions to install: [17:19:01.240] Install and start server if needed [17:19:01.242] PATH: /opt/ros/noetic/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin [17:19:01.242] Checking ssh with "ssh -V" [17:19:01.246] > OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f 31 Mar 2020 [17:19:01.249] askpass server listening on /run/user/1000/vscode-ssh-askpass-df933a953e2bc1cfcb9bb95d0bc0fecafad40ee3.sock [17:19:01.249] Spawning local server with {"serverId":1,"ipcHandlePath":"/run/user/1000/vscode-ssh-askpass-2285b44bb52479af6e1b8f50870389b6f1e7301c.sock","sshCommand":"ssh","sshArgs":["-v","-T","-D","43071","-o","ConnectTimeout=15","127.0.1.1"],"serverDataFolderName":".vscode-server","dataFilePath":"/home/ubuntuworld/.config/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-23c6a5dd-488a1f239235055e34e673291fb8d8c810886f81-0.120.0-es/data.json"} [17:19:01.249] Local server env: {"SSH_AUTH_SOCK":"/run/user/1000/keyring/ssh","SHELL":"/bin/bash","DISPLAY":":0","ELECTRON_RUN_AS_NODE":"1","SSH_ASKPASS":"/home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/local-server/askpass.sh","VSCODE_SSH_ASKPASS_NODE":"/usr/share/code/code","VSCODE_SSH_ASKPASS_EXTRA_ARGS":"","VSCODE_SSH_ASKPASS_MAIN":"/home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/askpass-main.js","VSCODE_SSH_ASKPASS_HANDLE":"/run/user/1000/vscode-ssh-askpass-df933a953e2bc1cfcb9bb95d0bc0fecafad40ee3.sock"} [17:19:01.252] Spawned 5361 [17:19:01.252] Using connect timeout of 17 seconds [17:19:01.298] > local-server-1> Running ssh connection command: ssh -v -T -D 43071 -o ConnectTimeout=15 127.0.1.1 [17:19:01.300] > local-server-1> Spawned ssh, pid=5370 [17:19:01.301] stderr> OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f 31 Mar 2020 [17:19:01.302] stderr> ssh: connect to host 127.0.1.1 port 22: Connection refused [17:19:01.302] > local-server-1> ssh child died, shutting down [17:19:01.304] Local server exit: 0 [17:19:01.304] Received install output: local-server-1> Running ssh connection command: ssh -v -T -D 43071 -o ConnectTimeout=15 127.0.1.1 local-server-1> Spawned ssh, pid=5370 OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f 31 Mar 2020 ssh: connect to host 127.0.1.1 port 22: Connection refused local-server-1> ssh child died, shutting down [17:19:01.304] WARN: $PLATFORM is undefined in installation script output. Errors may be dropped. [17:19:01.305] Failed to parse remote port from server output [17:19:01.307] Resolver error: Error at y.Create (/home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:744751) at t.handleInstallOutput (/home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:742832) at e (/home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:798600) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async /home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:823806 at async t.withShowDetailsEvent (/home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:827501) at async /home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:795312 at async P (/home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:793367) at async t.resolveWithLocalServer (/home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:794864) at async A (/home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:820659) at async t.resolve (/home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:824898) at async /home/ubuntuworld/.vscode/extensions/ms-vscode-remote.remote-ssh-0.120.0/out/extension.js:2:1113660 [17:19:01.310] ------ [17:19:01.311] No hints found in the recent session.什么原因?
最新发布
08-01
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值