3
submitted 10 months ago by 1c34@alien.top to c/main@selfhosted.forum

i want to remotely ssh to my home server, and I was wondering if I could just forward port 22 with disabling password login and use pubkey authentication will be safe enough?

top 50 comments
sorted by: hot top controversial new old
[-] chaplin2@alien.top 3 points 10 months ago

If you disable password authentication, and use public key authentication, yes.

[-] kaipee@alien.top 3 points 10 months ago

Disable password auth.

Enable key only auth.

Add in TOTP 2FA (google authenticator).

Randomize the port (reduce bots) that forwards to 22.

Configure lockout to block upon 3 failed attempts, for a long duration like 1 year. (Have a backup access on LAN).

Ensure only the highest encryption ciphers are accepted.

Ensure upgrades are applied to sshd at least monthly.

[-] gnordli@alien.top 2 points 10 months ago

If you are going all out, may as well add hosts.deny and hosts.allow.

[-] kaipee@alien.top 1 points 10 months ago

Easy to do with known internal networks.

Difficult to manage when roaming.

[-] gnordli@alien.top 1 points 10 months ago

Absolutely, just sometimes people forget those tools even exist. Of course, you can easily do the same thing with firewall rules as well.

Also, that was a great tidbit about the pam email notification on successful logon. I haven't seen that one before, thank you!!

load more comments (1 replies)
[-] ennova2005@alien.top 1 points 10 months ago

Good summaries. How does the TOTP 2FA article handle drop/reconnects? TOTP needed for each reconnect attempt?

[-] blackstar2043@alien.top 1 points 10 months ago

To help with identifying issues within your SSHd configuration, I recommend using ssh-audit: https://github.com/jtesta/ssh-audit

load more comments (1 replies)
[-] brandontaylor1@alien.top 3 points 10 months ago

As long as password auth is disabled you’re fine. No one is cracking your RSA key. You can add Fail2Ban to reduce the log noise, but security wise it’s fine.

[-] Hatta00@alien.top 1 points 10 months ago

Change your port.

No one's cracking a proper implementation of RSA, but not every implementation is proper. A little obscurity can't hurt.

load more comments (7 replies)
[-] Beastmind@alien.top 1 points 10 months ago

Also don't use rsa, use Ed25519 nowadays

load more comments (7 replies)
[-] DarthNihilus@alien.top 1 points 10 months ago

Realistically no one is cracking my super long randomized password either. Seems fine to leave it on as backup login.

load more comments (1 replies)
[-] AnApexBread@alien.top 3 points 10 months ago

disabling password login and use pubkey authentication will be safe enough?

Just make sure you actually disable password login. Simply enabling key doesn't disable password. So as long as the password is disabled then you're fine.

[-] no_step@alien.top 2 points 10 months ago

I run this on port 22 and ssh with keys on a different port

[-] Both-Following9917@alien.top 2 points 10 months ago

Get fail2ban setup at a minimum

[-] mrpink57@alien.top 2 points 10 months ago

No. Just VPN in and SSH in.

[-] kaipee@alien.top 3 points 10 months ago

How is a VPN service more secure than an SSH service?

Both accept login.

Both provide can be brute forced / if using password.

[-] Internal-Initial-835@alien.top 1 points 10 months ago

Generally speaking. VPN is easier to setup securely out of the box for most especially with limited knowledge. You can choose a random port and then have access to any server on your network. Scanners won’t usually test all ports unless they find something that’s tempting.

Normally just the normal ports will be poked including 22. SSH can be secured well but not without jumping through a few hoops. It’s easier imho to accidentally allow access through incorrect ssh setup than vpn.

When you think vpn has been developed with this exact purpose in mind. It’s fair to assume the protection will be better out of the box. If you have a vpn then a hacker needs to get through the vpn and then also the ssh so there’s not really any disadvantage to using a vpn and then also harden ssh if you want to.

It’s about making things difficult. Nobody is going to spend days or weeks battering a vpn if they don’t think there’s anything useful behind it. A VPN also shows somewhat that you’ve given things consideration and are not an easy target.

Don’t get me wrong. If somebody is determined enough and has the resources then they will find a way but given the choice between an easy target and one that’s ever so slightly more difficult, they will almost always go for the easiest.

[-] Karyo_Ten@alien.top 1 points 10 months ago

VPN is easier to setup securely out of the box for most especially with limited knowledge.

One of the top audit companies disagrees with you: https://blog.trailofbits.com/2016/12/12/meet-algo-the-vpn-that-works/

load more comments (1 replies)
load more comments (1 replies)
load more comments (1 replies)
[-] Bloodrose_GW2@alien.top 2 points 10 months ago

Better use some kind of VPN and only open the SSH port over the VPN interface.

[-] BinniH@alien.top 1 points 10 months ago

Set up free Tailscale and access your server that way.

[-] gentooxativa@alien.top 1 points 10 months ago

Is always better to randomize your ssh port, you will be safe from some scans

[-] foomatic999@alien.top 1 points 10 months ago

Using a non-standard port for SSH doesn't make it safer but it greatly reduces noise in your logs. If you only use it yourself, change the port.

[-] mshorey81@alien.top 1 points 10 months ago

Most likely it's fine. Though it's not terribly difficult to set up some flavor of VPN so you're not exposing 22 at all outside your network. Personally I use Wireguard.

[-] mcr1974@alien.top 1 points 10 months ago

but you still have to expose something to connect to wireguard?

[-] mshorey81@alien.top 1 points 10 months ago

Of course. But it's just another layer to the onion. Pfblockerng, Crowdsec, Fail2Ban, wireguard....layers.

[-] mcr1974@alien.top 1 points 10 months ago

but wouldn't you have to pay a performance penalty running ssh on top of wireguard.

load more comments (2 replies)
[-] Swanners@alien.top 1 points 10 months ago

I would not do this, people port scan all the time and thats an easy one to look for. Try using an at home vpn like openvpn or in the very least change the ssh port to something odd like 6854 or whatever.

[-] astronautcytoma@alien.top 1 points 10 months ago

I have a port 22 ssh process that denies everything, and a separate ssh process on a different port that accepts logins as normal. So someone could obviously find the hidden one, but it won't be the apparently-functional one that they can hit day and night and never get any results from.

[-] Swanners@alien.top 1 points 10 months ago

Fair enough. If you can run firewall rules then great. But opening up something like ssh to the internet is a risky risk. Cert auth is not a bad way to go in that scenario.

[-] astronautcytoma@alien.top 1 points 10 months ago

I agree entirely. The box I have this on is my piddle-around server. A long time ago I used to administer a medium-sized cluster of Linux boxes and they were all cert auth, and I wouldn't have had it any other way. Mostly, I think it's fun to see what usernames and passwords the scripts and bots and hackers try on my neutered SSH.

[-] InevitableArm3462@alien.top 1 points 10 months ago

I recommend implementing a VPN (wireguard is working very well for me) and through that do ssh

[-] returnofblank@alien.top 1 points 10 months ago

A VPN will always be better for this purpose, but as long as you properly secure your SSH server, shouldn't be a problem

[-] billiarddaddy@alien.top 1 points 10 months ago

Move it to a four digit port on your router and port for to 22 internally.

[-] ripnetuk@alien.top 1 points 10 months ago

I would risk it. After all, it's the only thing protecting my entire gitlab account. If someone could break my ssh, they could do what they want to my gitlab presence,and I'm guessing someone at gitlab is paid and qualified to make that call.

[-] InfaSyn@alien.top 1 points 10 months ago

With PubKey and Fail2Ban its probably ok but wouldnt chance it personally. Can you use a different port too?

[-] Internal-Initial-835@alien.top 1 points 10 months ago

In a word no. That’s not a port you want others sniffing around. Some isps actively block that port for security. IMHO a vpn is the best way. That way you get full access to your network as if you’re using a wired direct connection. You “can” use port 22 and you can make it pretty secure but I just wouldn’t feel safe directly exposing it when there are other ways. Imagine the access somebody could get if you do something slightly wrong or you miss a patch for a new vulnerability. Yep it’s unlikely but why risk it. Put it behind something on a none standard port rather than a port that every sniffer will poke at :)

[-] ezpzCSGO@alien.top 1 points 10 months ago

In my case, password auth disabled, changed port, fail2ban, and not exposing the port, I connect through vpn and then ssh, but in the end it's still an open port for the vpn

[-] Cylian91460@alien.top 1 points 10 months ago

Yes, but you should change the port

[-] uncmnsense@alien.top 1 points 10 months ago

Rather than port forward 22, I would recommend using the ipv6 address and securing the host.

load more comments (1 replies)
[-] jerwong@alien.top 1 points 10 months ago

Yes, it's perfectly safe. Keep it patched, use strong ciphers, use key authentication, and set up an IDS like Fail2Ban or CrowdSec.

[-] Innominate8@alien.top 1 points 10 months ago

A tremendous amount of cargo culting going on here.

As long as your server is aggressively kept up to date and doesn't have any guessable passwords, exposing port 22 can be done safely. If you're not certain about these, you shouldn't. OpenSSH is exposed to the open internet on millions of servers, it's meant to do this.

Fail2ban or changing your ssh port provides no additional security and only serves to reduce log noise at the risk of blocking actual users.

A VPN makes no practical difference. ssh uses strong encryption just like the VPN. Sure you're hiding ssh, but the VPN provides a similar attack surface.

[-] kihaji@alien.top 1 points 10 months ago

If you're not certain about these, you shouldn't.

If someone is asking random assholes on the internet if they should do something, I'm guessing the answer to this is no.

load more comments (1 replies)
[-] ayoungblood84@alien.top 1 points 10 months ago

I wouldn't open up 22 to the world. I would change the port at a minimum or use a VPN.

load more comments (3 replies)
[-] blusls@alien.top 1 points 10 months ago

Depending on how you will be connecting depends on how you should configure this. I would strongly suggest just setting up a Wireguard server and connect to it via VPN. At the same time, exposing the port and using a pubkey with Fail2Ban would be the next best option, while always keeping your server patched with port forwarding a different port to the stand SSH port internally.

These are the simplest ways to do this and still be secure. Again, I strongly suggest setting up a private VPN of your choosing.

WireGuard Installs - https://www.wireguard.com/install/

WireGuard Docker - https://github.com/wg-easy/wg-easy

[-] imthefrizzlefry@alien.top 1 points 10 months ago

Using an alternate port will drastically cut down on the number of people trying to brute force your server

load more comments
view more: next ›
this post was submitted on 28 Nov 2023
3 points (100.0% liked)

Self-Hosted Main

502 readers
1 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

For Example

We welcome posts that include suggestions for good self-hosted alternatives to popular online services, how they are better, or how they give back control of your data. Also include hints and tips for less technical readers.

Useful Lists

founded 1 year ago
MODERATORS