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?

  • @kaipeeB
    link
    fedilink
    English
    37 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.

    • @gnordliB
      link
      fedilink
      English
      27 months ago

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

      • @Kazer67B
        link
        fedilink
        English
        17 months ago

        Add port knocking, if we go all out, let’s go all out!

      • @kaipeeB
        link
        fedilink
        English
        17 months ago

        Easy to do with known internal networks.

        Difficult to manage when roaming.

        • @gnordliB
          link
          fedilink
          English
          17 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!!

    • @sidusnareB
      link
      fedilink
      English
      17 months ago

      Configure lockout to block upon 3 failed attempts

      fail2ban

    • @ennova2005B
      link
      fedilink
      English
      17 months ago

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

  • @chaplin2B
    link
    fedilink
    English
    37 months ago

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

  • @brandontaylor1B
    link
    fedilink
    English
    37 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.

      • @SR_Lut3t1umB
        link
        fedilink
        English
        17 months 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.

      • @upofadownB
        link
        fedilink
        English
        17 months ago

        RSA is fine. It isn’t like you will have to worry about the length of the keys for SSH.

        • @BeastmindB
          link
          fedilink
          English
          17 months ago

          It is but if you’re going to use something security related, use the current recommendation unless you stricly can’t for legacy reason or something.

          • @upofadownB
            link
            fedilink
            English
            17 months ago

            I think that legacy reason in this case would be already having RSA keys. The point is that you don’t have to go through the bother of replacing them.

        • @mr_whats_it_to_youB
          link
          fedilink
          English
          17 months ago

          Well it‘s true that one can use RSA, which is still save with keys big enough, but if someone wants so save some extra computing power and time ed25519 is the way to go.

          • @dumbasPLB
            link
            fedilink
            English
            17 months ago

            The difference is extremely tiny because asymmetric encryption is only used at the very beginning to securely establish a symmetric key that will be used for everything else afterwards. So you would have to be running this on a smart fridge to notice the speed difference.

          • @upofadownB
            link
            fedilink
            English
            17 months ago

            Requires an actual hardware error. Almost all implementations, including all open source SSH implementations, check that the signature is valid thus preventing a cosmic ray induced bit flip from triggering this issue and any related issue.

            What effect do hardware errors have on Ed25519?

    • @mshriver2B
      link
      fedilink
      English
      17 months ago

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

    • @Hatta00B
      link
      fedilink
      English
      17 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.

      • @pentesticalsB
        link
        fedilink
        English
        17 months 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.

        • @OujiiB
          link
          fedilink
          English
          17 months ago

          only logs will be real people.

          There are bots that scan for open ports in minutes.

          • @Karyo_TenB
            link
            fedilink
            English
            17 months ago

            But then it’s blatantly obvious and you can behavior block.

            • @dal8mocB
              link
              fedilink
              English
              17 months 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_TenB
                link
                fedilink
                English
                17 months 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.

          • @pentesticalsB
            link
            fedilink
            English
            17 months 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.

    • @DarthNihilusB
      link
      fedilink
      English
      17 months ago

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

  • @AnApexBreadB
    link
    fedilink
    English
    37 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.

  • @Bloodrose_GW2B
    link
    fedilink
    English
    27 months ago

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

    • @kaipeeB
      link
      fedilink
      English
      37 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.

      • @sdR-h0m13B
        link
        fedilink
        English
        17 months 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.

      • @Internal-Initial-835B
        link
        fedilink
        English
        17 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.

          • @Internal-Initial-835B
            link
            fedilink
            English
            17 months 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 :)

    • @Scruffy-NerdB
      link
      fedilink
      English
      17 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

  • @SamSausagesB
    link
    fedilink
    English
    17 months 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.

  • @InevitableArm3462B
    link
    fedilink
    English
    17 months ago

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

  • @gentooxativaB
    link
    fedilink
    English
    17 months ago

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

    • @foomatic999B
      link
      fedilink
      English
      17 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.

  • @mshorey81B
    link
    fedilink
    English
    17 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.

    • @mcr1974B
      link
      fedilink
      English
      17 months ago

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

      • @davis-andrewB
        link
        fedilink
        English
        17 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.

      • @mshorey81B
        link
        fedilink
        English
        17 months ago

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

        • @mcr1974B
          link
          fedilink
          English
          17 months ago

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

  • @SwannersB
    link
    fedilink
    English
    17 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.

    • @astronautcytomaB
      link
      fedilink
      English
      17 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.

      • @SwannersB
        link
        fedilink
        English
        17 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.

        • @astronautcytomaB
          link
          fedilink
          English
          17 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.

  • @billiarddaddyB
    link
    fedilink
    English
    17 months ago

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

  • @InfaSynB
    link
    fedilink
    English
    17 months ago

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