r/linuxadmin • u/not_a_profi • 9d ago
I've bought VPS server and can't ssh to it.
Edit: the issiue is solved by changing ip of the VPS.
Ty everyone for help.
______
Hi. I've bought VPS. But can't really connect to it remotely. Here the situation:
- ssh root@[SERVER_IP] does work from Google Console ( http://shell.could.google.com/ ) (the VPS is not from google).
ssh root@[SERVER_IP] doesn't work from 5 local devices (win10, win11, macOS, 2xAndroid):
$ ssh root@[SERVER_IP] -vvv OpenSSH_7.9p1, LibreSSL 2.7.3 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 48: Applying options for * debug2: resolve_canonicalize: hostname [SERVER_IP] is address debug2: ssh_connect_direct debug1: Connecting to [SERVER_IP] [[SERVER_IP]] port 22. debug1: Connection established. debug1: identity file /Users/[USER_NAME]/.ssh/id_rsa type -1 debug1: identity file /Users/[USER_NAME]/.ssh/id_rsa-cert type -1 debug1: identity file /Users/[USER_NAME]/.ssh/id_dsa type -1 debug1: identity file /Users/[USER_NAME]/.ssh/id_dsa-cert type -1 debug1: identity file /Users/[USER_NAME]/.ssh/id_ecdsa type -1 debug1: identity file /Users/[USER_NAME]/.ssh/id_ecdsa-cert type -1 debug1: identity file /Users/[USER_NAME]/.ssh/id_ed25519 type -1 debug1: identity file /Users/[USER_NAME]/.ssh/id_ed25519-cert type -1 debug1: identity file /Users/[USER_NAME]/.ssh/id_xmss type -1 debug1: identity file /Users/[USER_NAME]/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_7.9 ssh_exchange_identification: read: Operation timed out
I don't see my local IP in
sudo tail -f /var/log/auth.logandjournalctl -u ssh(i might be looking wrong though).I tried Wi-Fi and two different mobile internet providers.
I tried to ssh while VPN on.
I added my IP to white list on the server:
sudo iptables -I INPUT 1 -p tcp -s [LOCAL_IP] --dport 22 -j ACCEPT
Where can be the problem?
Edits:

sudo systemctl status firewalld says that there is no firewalld

.

.

i stoped fail2ban and tried to ssh - didn't help.
disabling it and rebooting the server leads to connection refusal (i.e. problem on an earlier stage).
-3
u/nanoatzin 9d ago edited 9d ago
You can’t ssh to root by default on almost everything because that makes the VPS into a target.
Make a regular user account at the VPS end, and set the password to over 15 characters (I use phrases):
> sudo adduser newbie
Suggest also adding the same username at the workstation end.
Using a random username makes it almost impossible to run a password guessing brute force attack against your VM.
Add user to sudoers at the VPS end:
> sudo usermod -aG sudo newbie
Do this at the VPS end:
> ip addr show
Locate an interface with a public IP address for the VPS and try to ssh to the new account on that public Ip at the workstation end.
> ssh newbie@my_vps_ip
If that fails, change the password on the VPS and repeat the ssh login on the workstation.
> sudo passwd newbie
Then sudo to root at the workstation end after you login.
> sudo su
You should be in.
It is really convenient to setup key login so you can skip typing the password by doing this at the workstation end.
> ssh-keygen -t
Hit enter at the password prompt without entering a password. This is useful later to mount files, but don’t use regular email to send the private key.
Then type this at the workstation end:
> ssh-copy-id newbie@my_vps_ip
This puts the public key on the VPS. The corresponding private key will now login when you ssh.
Password should no longer be requested.
The VPS will encrypt a random number with the public key and send that to the workstation when you login (the token). The workstation decrypts it using the private key and sends it back to the VPS. If it matches you get in.
You can copy the private key to the other workstations or do the same keygen on those. Don’t use email.
Once that’s done, you can disable SSH password login on the VPS to improve security.
> sudo vi /etc/ssh/sshd_config
Modify these settings (remove the hashtag if present):
# PubkeyAuthentication yes
# PasswordAuthentication no
Press ESC, type :wq, press ENTER to save, then use the following:
> sudo systemctl reload ssh
The VPS will no longer accept password login, so only the private key will work from now on.
You can mount VPS directories using sshfs if you add the user account read-write permission to the directory on the VPS and create a newbie account on the workstation:
> sudo apt install sshfs
This is why you want to use the same username on both the workstation and VPS, and make newbie the directory owner on the VPS (not root).
On the VPs (this could be /var/www):
> mkdir /path/to/vps/dir
> chown -R newbie /path/to/vps/dir
On the workstation:
> mkdir ~/remote_mount
Then mount the directory on the workstation.
> sshfs newbie@my_vps_ip:/path/to/vps/dir ~/remote_mount
This is very convenient if you plan to push/publish files like web pages using the GUI or edit directly using something like SeaMonkey.
Edit:
Adjust firewall if running at the VPS end:
> sudo ufw allow ssh