0

I tried to connect to my sever through the ssh using ubuntu but it does not work.

 sudo apt-get install openssh-server openssh-client
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
openssh-client is already the newest version (1:8.2p1-4ubuntu0.3).
openssh-client set to manually installed.
openssh-server is already the newest version (1:8.2p1-4ubuntu0.3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
user@12122017-Dell:~$ ssh localhost
ssh: connect to host localhost port 22: Connection refused

I don't know what i am missing. What should i do? Please help me. Thank a lot

Newbie
  • 1
  • 1
  • 1
    Welcome, the host must have the port 22 open. You can open ports with ufw (you have to install it). – schrodingerscatcuriosity Sep 29 '21 at 12:32
  • 1
  • 1
    @schrodigerscatcuriosity UFW wouldn't block connections via the localhost interface AFAIK – steeldriver Sep 29 '21 at 12:38
  • So the SSH server is installed - have you verified that it is actually running (systemctl status ssh or service ssh status for example) and listening on the default port 22 (sudo netstat -nlpt | grep sshd) – steeldriver Sep 29 '21 at 12:42
  • A VPN will block local connections in some cases. – David Sep 29 '21 at 12:42
  • @steeldriver right! I commented in the general way, but OP's is trying with localhost then. – schrodingerscatcuriosity Sep 29 '21 at 12:49
  • Thank you. So i have a remote server. Should i try it with my server to see how it's going? – Newbie Sep 30 '21 at 07:25
  • I tried and here was the result.

    `user@12122017-Dell:~$ systemctl status ssh

    System has not been booted with systemd as init system (PID 1). Can't operate.

    Failed to connect to bus: Host is down

    user@12122017-Dell:~$ sudo systemctl start ssh

    [sudo] password for user:

    System has not been booted with systemd as init system (PID 1). Can't operate.

    Failed to connect to bus: Host is down`

    What should i do.

    – Newbie Sep 30 '21 at 07:29
  • It looks like systemd is not installed. Which version of Ubuntu are you using? – user68186 Sep 30 '21 at 19:05
  • can you install net-tools by sudo apt update and sudo apt install net-tools then execute netstat -tulpn4 and add the output to your question ? that should show if your computer is listening to ssh service. another thing that i missed up, are you trying to connect a server? can you be more specific about what pc you are using and what machine you are trying connect to ? – CrazyTux Sep 30 '21 at 19:44
  • I did every thing and here is the result
    (No info could be read for "-p": geteuid()=1000 but you should be root.)
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name```
    I wanted to connect to a hosting sever which i rented, i got a shop on that sever but it is too laggy so i tried to connect through the ssh and install some cached on it to see how it's going. I am using a dell laptop. the processor ```Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz   2.50 GHz```
    
    – Newbie Oct 01 '21 at 13:26
  • have you installed the open-ssh program on your server as well? try to run the netstat -tulpn4 on your server after installing net-tools on the server. – CrazyTux Oct 01 '21 at 13:29
  • I tried the ssh mysever@IP sever and i got. ssh: connect to host IP port 22: Resource temporarily unavailable. What does this mean and what should i do. – Newbie Oct 01 '21 at 15:10

1 Answers1

0

As you have already tried, it's definitely worth trying ssh to your localhost, to see if it's listening locally:

ssh username@localhost

If this works but you can't get it from another computer, it's probably something with your network connection, including firewwall

In your case, this doesn't work so it's unlikely to be network connection or firewall.

Have you checked that the ssh service is running?

systemctl status ssh

It should say active. If it doesn't, try starting the ssh server:

sudo systemctl start ssh
# or - alternative - if not using systemd
sudo /etc/init.d/ssh start

A machine restart is also worth trying.

moo
  • 878
  • I tried and here was the result.

    `user@12122017-Dell:~$ systemctl status ssh

    System has not been booted with systemd as init system (PID 1). Can't operate.

    Failed to connect to bus: Host is down

    user@12122017-Dell:~$ sudo systemctl start ssh

    [sudo] password for user:

    System has not been booted with systemd as init system (PID 1). Can't operate.

    Failed to connect to bus: Host is down`

    What should i do.

    – Newbie Sep 30 '21 at 07:27
  • DId you try an internet search? https://linuxhandbook.com/system-has-not-been-booted-with-systemd/ sudo service ssh start if that doesn't work, try sudo /etc/init.d/sshd start – moo Sep 30 '21 at 19:10
  • Thank you i will try it. Thank you a lot. – Newbie Oct 01 '21 at 13:22
  • I tried and here is what i got
     * Starting OpenBSD Secure Shell server sshd                                                                            sshd: no hostkeys available -- exiting.```
    What should i do
    
    – Newbie Oct 01 '21 at 13:28
  • Try an internet search. Maybe with the search term sshd: no hostkeys available -- exiting. I think you might be able to solve it... – moo Oct 01 '21 at 17:03
  • Thank you i will try it. – Newbie Oct 01 '21 at 17:22
  • 1
    And now this answer is the top result when searching for the 'no hostkeys error' :) – Ian Newson Mar 24 '22 at 16:33
  • Ok, so the irony is not lost on me!! The point I was trying to make is that the answer is already out there and I was trying to encourage a little bit of research rather than spoon feeding. However, it seems the situation has now changed if this is the top answer! – moo Mar 24 '22 at 19:10