Score:0

Connecting to sever through ssh

cn flag

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

schrodigerscatcuriosity avatar
au flag
Welcome, the host must have the port 22 open. You can open ports with `ufw` (you have to install it).
ar flag
Does this answer your question? [Connect two computers with SSH in a home LAN](https://askubuntu.com/questions/1107987/connect-two-computers-with-ssh-in-a-home-lan)
hr flag
@schrodigerscatcuriosity UFW wouldn't block connections via the localhost interface AFAIK
hr flag
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`)
David avatar
cn flag
A VPN will block local connections in some cases.
schrodigerscatcuriosity avatar
au flag
@steeldriver right! I commented in the general way, but OP's is trying with localhost then.
Newbie avatar
cn flag
Thank you. So i have a remote server. Should i try it with my server to see how it's going?
Newbie avatar
cn flag
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.
ar flag
It looks like `systemd` is not installed. Which version of Ubuntu are you using?
CrazyTux avatar
us flag
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 ?
Newbie avatar
cn flag
I did every thing and here is the result ```user@12122017-Dell:~$ netstat -tulpn4 (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```
CrazyTux avatar
us flag
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.
Newbie avatar
cn flag
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.
Score:0
cg flag

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.

Newbie avatar
cn flag
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.
cg flag
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`
Newbie avatar
cn flag
Thank you i will try it. Thank you a lot.
Newbie avatar
cn flag
I tried and here is what i got ```user@12122017-Dell:~$ sudo service ssh start * Starting OpenBSD Secure Shell server sshd sshd: no hostkeys available -- exiting.``` What should i do
cg flag
Try an internet search. Maybe with the search term *sshd: no hostkeys available -- exiting.* I think you might be able to solve it...
Newbie avatar
cn flag
Thank you i will try it.
Ian Newson avatar
us flag
And now this answer is the top result when searching for the 'no hostkeys error' :)
cg flag
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!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.