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?

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

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

      • SR_Lut3t1um@alien.topB
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        Dont connect it to the internet too. Chances are even less likely that some navy seals kinda guys will steal you data with brute force. Also always keep explosives next to your hdds so once they do come you can explode them.

    • DarthNihilus@alien.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

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

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

      • pentesticals@alien.topB
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        Just waiting for everyone to come in saying you shouldn’t do this lol. Yes, changing the port is a nice little bonus. It doesn’t any extra security, but it moves you out of the way from the automated bots that scan the internet trying recent 0days. You’ll probably see a reduction of 99% traffic hitting the service and the only logs will be real people.

        • Oujii@alien.topB
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          only logs will be real people.

          There are bots that scan for open ports in minutes.

            • dal8moc@alien.topB
              link
              fedilink
              English
              arrow-up
              1
              ·
              1 year ago

              Which is easily defeated by using one block of ip addresses to gather data and another block for actually trying to exploit found ports. Unless you block the whole AS. If the attacker only uses one system with one ip they probably wouldn’t have the resources to get past ssh anyway.

              • Karyo_Ten@alien.topB
                link
                fedilink
                English
                arrow-up
                1
                ·
                1 year ago

                Behavior blocking can be done across many IPs.

                If you have one IP that scans port 10000, the other port 10001, and thousands of other IPs scanning just 1 port it’s still blatantly obvious.

                And if they want to scan in a less obvious manner they need to do this spaced by days.

          • pentesticals@alien.topB
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 year ago

            Yes but most bots are scanning for common ports. It’s far too slow to scan 65k ports on every host. Even things like shodan only scan a handful of common ports. But you can test this yourself, expose SSH on a port number in 20-40ks, I’ve seen several weeks without a single probe.

            If you’ve ever done mass scanning you know that’s minutes is not going to to be a full scan and if you are trying to do 65k ports in a few minutes, your results will not be accurate.

    • mshriver2@alien.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      If you really want security you should also add UFW and restrict it to only your IP address.

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

        Easy to do with known internal networks.

        Difficult to manage when roaming.

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

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

  • chaplin2@alien.topB
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 year ago

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

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

          • Internal-Initial-835@alien.topB
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 year ago

            A “top” audit company pushing their own agenda.

            OpenVPN is simple and easy to deploy on any major operating system. Pfsense or similar is easy to setup and run in a VM. That does all the hard work for you and creates a profile. Then you essentially copy or download that profile to the client machine and you’re done. It’s all done via gui or web interface so is easier for a lot of people. My sister managed it. She wouldn’t have been able to handle command line stuff.

            Like i said before though. Why not use a vpn and also harden your ssh. I can’t see a downside to that.

            It’s just my opinion and experience from working with both. You’re welcome to dissagree and do your own thing though of course :)

      • sdR-h0m13@alien.topB
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        WireGuard uses UDP and will not respond if the attacker doesn’t have the correct key. So the port used by WG will appears as a closed port.

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

  • marbonmb@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I know that some VPN are able to create private networks for devices logged with your account. For exemple nordvpn is able to connect your devices into their “mesh network” and make your devices available through the VPN. I think it’s better than exposing a ssh service on Internet, even with a lot of protections!

  • Gabe_Isko@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Honestly? Would not recommend it. Probably no one breaking in soon, but there are just constantly tons of botnets portscanning 22 over the whole IP range. You should at least think of switching ports, but I usually recommend at least having a vpn for ssh.

  • eirsik@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    SSH exposed with key auth and not password is fine. It is the exact purpose of SSH after all. Also there are milions of web servers out there with exposed SSH because a lot of their users prefer to work with SSH and CLI instead of a web UI. Big hosts such as GoDaddy, BlueHost, Hostgate and so on, all expose their SSH. You don’t see their servers crash and burn every week.

  • Prof-Mmaa@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I keep ssh on port 80, multiplexed with usual HTTP traffic thanks to sslh. Basically it’s a protocol switchboard what detects what kind of traffic reaches your server and forwards it to appropriate service. It can distinguish between SSH/HTTP/OpenVPN and a few more.

    Pros? Security wise probably nothing more that SSH already offers, but port 80 is rarely (if ever) blocked on other networks and having SSH on port that is non-standard and obscured, cuts way down on random attempts to guess the user/password combination.

  • blackstar2043@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    This is my current hardened sshd configuration.

    ssh/sshd_config: https://pastebin.com/7tH36TdJ

    • Public key authentication and 2fa using oathtool are used to authenticate.
    • Logging in is only possible for members of the ‘ssh-user’ group.
    • “root” login is disabled through “PermitRootLogin”, “DenyGroups”, and “DenyUsers”.
    • “restricted” has the ability to log in from any host.
    • “user” is limited to using the internal network to log in.
    • ‘admin’ can only log in when connected via WireGuard.
    • “sftp” may login, but only uses the sftp server. There is no shell available.

    pam.d/sshd: https://pastebin.com/eqkisf4F

    • All successful pre-2FA logins will trigger the ‘ssh-login-alert’, which sends an NTFY alert containing the time, date, user, and host IP.
    • The use of /etc/users.deny prevents root login.
    • The use of /etc/users.allowed permits login by “restricted”, “user”, “admin” and “sftp”.
    • 2FA and ssh-login-alert trigger do not apply to “sftp”
  • SamSausages@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Yes and no.

    Yes if you have the resources to monitor and update. Companies have entire teams dedicated to this.

    No if you don’t have the resources/time to keep up with it regularly.

    IMO, no need to take this risk when you have services like Tailscale available today.