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?

  • brandontaylor1@alien.topB
    link
    fedilink
    English
    arrow-up
    3
    ·
    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.

  • chaplin2@alien.topB
    link
    fedilink
    English
    arrow-up
    3
    ·
    10 months ago

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

  • kaipee@alien.topB
    link
    fedilink
    English
    arrow-up
    3
    ·
    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.

      • kaipee@alien.topB
        link
        fedilink
        English
        arrow-up
        1
        ·
        10 months ago

        Easy to do with known internal networks.

        Difficult to manage when roaming.

        • gnordli@alien.topB
          link
          fedilink
          English
          arrow-up
          1
          ·
          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!!

    • ennova2005@alien.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      10 months ago

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

  • AnApexBread@alien.topB
    link
    fedilink
    English
    arrow-up
    3
    ·
    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.

    • kaipee@alien.topB
      link
      fedilink
      English
      arrow-up
      3
      ·
      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.topB
        link
        fedilink
        English
        arrow-up
        1
        ·
        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.

    • Scruffy-Nerd@alien.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      10 months ago

      I think many ppl are missing a step here. Setup a VPN with wireguard or similar. Then in ur sshd configs only allow ssh from ur VPN local subnet. That on top of ssh key login is pretty secure. Unless one of ur other services gets compromised and they pivot to ur VPN network. Then u prob have more problems tbh

  • dev_all_the_ops@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 months ago

    Port forwarding will work, but it has major downsides

    1. Will draw attention of bots
    2. Secure as long as there are no security holes in openssh (which is rare but has happened)
    3. You _must_ harden the ssh server by disabling password auth, putting behind fail2ban

    There are far better and safer alternatives that I would recommend over exposing a raw port to the world.

    1. Tailscale
    2. Wireguard/OpenVPN
    • Innominate8@alien.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      10 months ago
      1. The bots are looking anyways.
      2. The other options being presented are various VPNs. OpenSSH has far more eyes on it, for much longer than any of the VPNs. Both generally run as root on the host and so have similar attack surfaces.
      3. Disabling password auth is less important than having good passwords, but is still a good idea since turning off passwords guarantees no bad passwords. Fail2ban provides no security.
    • foomatic999@alien.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      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.

  • Swanners@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    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.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      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.topB
        link
        fedilink
        English
        arrow-up
        1
        ·
        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.topB
          link
          fedilink
          English
          arrow-up
          1
          ·
          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.

  • mshorey81@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    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.

      • mshorey81@alien.topB
        link
        fedilink
        English
        arrow-up
        1
        ·
        10 months ago

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

        • mcr1974@alien.topB
          link
          fedilink
          English
          arrow-up
          1
          ·
          10 months ago

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

      • davis-andrew@alien.topB
        link
        fedilink
        English
        arrow-up
        0
        ·
        10 months ago

        The benefit of wireguard^ is it runs over udp and won’t respond unless a peer with the right key hits it. ie a port scan won’t reveal anything because there’s no tcp port open to handshake, and wireguard won’t respond to junk data coming in.

        ^ Most VPNs run over udp. But i’m not sure say OpenVPN will respond to random crap, it probably won’t but i don’t want to state categorically that it won’t.

  • InfaSyn@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 months ago

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