diff --git a/content/about.md b/content/about.md index b0a2ed4..d90155c 100644 --- a/content/about.md +++ b/content/about.md @@ -6,7 +6,7 @@ description = "About who I am" I'm Crony Akatsuki, 20 year old who doesn't go to college. Living in Croatia. At the current unemployed (Bored). I love linux, computer's and foss. -To pass time I read manga, program stupid little programs, +To pass time I read manga, watch movies/tv shows/anime, program stupid little programs, create bash scripts or find new software to self host. ## How I came up with my online name @@ -14,7 +14,7 @@ create bash scripts or find new software to self host. I used the `Cro` from Croatia and added `ny` just cause, I used `Akatsuki` cause its cool and I watched naruto way back when I didn't know what anime was on Serbian dub (Cause Croatia dumb enough to not dub -and showcase naruto, FUCK CROATIA!). +and showcase naruto). --- @@ -28,6 +28,6 @@ and showcase naruto, FUCK CROATIA!). ### Donations -If you think what I'm doing is good and worth it, you can give me a donation: +If you think what I'm doing is good and worth it, you can give me a tip: XMR: 84tePvZRoPhHNCzKiLNp8ET2wPUnPfbYsj3qCxJEJu7TdovYcPZbsXeVRKyFbFiTAXfzP8sPAHQnjGXwjFujVhqnBGoQQpK diff --git a/content/blog/securing-ssh.md b/content/blog/securing-ssh.md new file mode 100644 index 0000000..df21f8c --- /dev/null +++ b/content/blog/securing-ssh.md @@ -0,0 +1,102 @@ ++++ +title = 'Securing Ssh' +date = 2024-04-04T20:44:10+02:00 +draft = false ++++ + +As someone who has a couple of servers out in the open web, one of the main things I had to learn was how to secure it so people can't touch them. One of the main ways to do that is by hardening ssh. + +Here I will name a couple of settings and best practices to make sure your ssh is as secure as possible. + + +--- + +## Use key pairs + +One of the main practice to secure ssh is by using public/private ssh key pair and making ssh only allow connection with them, disabling password login. + +First you need to generate a key pair by running the commmand `ssh-keygen`. + +After generating the key and the command `ssh-copy-id ~/.ssh/key_name user@host` to copy the key to the server. + +Connection to the server now it will ask you for the ssh key password if you set one, if you didn't then it will just directly connect it. + +While you are connected to the server now, I would recommend you to change next settings to the values I recommend to make sure you can only connect to the server with ssh key pairs already on the server. Make sure to uncommmend the values in your config, and change like I did in my examples. + +> /etc/ssh/sshd_config +```conf +PubkeyAuthentication yes + +PasswordAuthentication no +PermitEmptyPasswords no +``` + +Restart your sshd service, with `systemctl restart sshd.service`. + +## Disable root user logins + +Next most common way to secure ssh is by not using a root account to connect, so even if somebody manages to connect they don't get root user access. + +After creating a new user ( make sure to add it to sudo/wheel group also ), make sure to copy the file located in `/root/.ssh/authorized_keys` to your new users directory in path `/home/user/.ssh/authorized_keys` + +I would reccommend at this point to try and connecting to the different user on the server to make sure the ssh keys were copied correctly. ( example `ssh new-user@host` ) + +After that, disable root user login and only allow connecting to ssh with the new user. + +> /etc/ssh/sshd_config +```conf +PermitRootLogin no +AllowUsers new-user +``` + +Restart your sshd service. + +## Only allow connection from specific ip + +Next best way to secure ssh is to only allow connection from specific ip, preferably vpn. + +Main way I do it is using wireguard. I set it up using the landchad [guide](https://landchad.net/wireguard). + +Then in your sshd config you can make it so that ssh will only accept connection to the user with only the current using syntax. + +```conf +AllowUsers new-user@172.16.0.2 +``` + +You can use the ip for the connection you use to setup the peer in the wireguard setup guide, which in landchad's guide is `172.16.0.2`. Or from another server by using the ip of the server you connect with wireguard to. + +Make sure to restart sshd and test out in another terminal window whether you can only connect with the wireguard connection to the server ( Don't close or exit the current ssh connection before making sure it all work's ). + +## General settings + +There are some more settings that can be changed and I will name them now. + +```conf +# Port change to allow connection from only that port, to connect use "ssh new-user@host -p port" +Port 4893 + +# Allow connection only from ipv4 +AddressFamily inet + +# Limit to only 3 connection tries +MaxAuthTries 3 + +# Disable pam +UsePAM no + +# Disable tcp and x11 forwarding +AllowTcpForwarding no +X11Forwarding no +``` + +If you by chance need tcp or x11 forwarding, enable it only for your user using this syntax: + +```conf +Match User new-user + AllowTcpForwarding yes + X11Forwarding yes +``` + +--- + +With this I have covered the most basic, but at the same best practices to secure your server ssh to not get uninvited people connecting to your servers. diff --git a/layouts/index.html b/layouts/index.html index b97e175..dbac99a 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -25,7 +25,8 @@

Currently mostly playing games and learning about nix and nixos, sometimes I - throw in a movie or a tv show in the mix tho. + throw in a movie or a tv show in the mix tho. Here is my nixos + config.

I'm an cli only person except when browsing the web or browsing the web, in diff --git a/public/about/index.html b/public/about/index.html index 341fb3f..d6f7d4c 100644 --- a/public/about/index.html +++ b/public/about/index.html @@ -44,13 +44,13 @@

I’m Crony Akatsuki, 20 year old who doesn’t go to college. Living in Croatia. At the current unemployed (Bored). I love linux, computer’s and foss. -To pass time I read manga, program stupid little programs, +To pass time I read manga, watch movies/tv shows/anime, program stupid little programs, create bash scripts or find new software to self host.

How I came up with my online name

I used the Cro from Croatia and added ny just cause, I used Akatsuki cause its cool and I watched naruto way back when I didn’t know what anime was on Serbian dub (Cause Croatia dumb enough to not dub -and showcase naruto, FUCK CROATIA!).

+and showcase naruto).


Contact Information

@@ -62,7 +62,7 @@ and showcase naruto, FUCK CROATIA!).

  • XMPP: crony@cronyakatsuki.xyz
  • Donations

    -

    If you think what I’m doing is good and worth it, you can give me a donation:

    +

    If you think what I’m doing is good and worth it, you can give me a tip:

    XMR: 84tePvZRoPhHNCzKiLNp8ET2wPUnPfbYsj3qCxJEJu7TdovYcPZbsXeVRKyFbFiTAXfzP8sPAHQnjGXwjFujVhqnBGoQQpK

    diff --git a/public/blog/index.html b/public/blog/index.html index 1a205b0..e7e8eb9 100644 --- a/public/blog/index.html +++ b/public/blog/index.html @@ -44,6 +44,9 @@
    + + 04-04-2024 || Securing Ssh
    + 19-01-2024 || Setup Traefik
    diff --git a/public/blog/index.xml b/public/blog/index.xml index e1239d6..8a1fd5e 100644 --- a/public/blog/index.xml +++ b/public/blog/index.xml @@ -6,11 +6,77 @@ Recent content in Blog on Crony Akatsuki's Website Hugo -- gohugo.io en-us - Fri, 19 Jan 2024 09:33:47 +0100 + Thu, 04 Apr 2024 20:44:10 +0200 + +Securing Ssh +https://cronyakatsuki.xyz/blog/securing-ssh/ +04-04-2024 + + https://cronyakatsuki.xyz/blog/securing-ssh/ +<p>As someone who has a couple of servers out in the open web, one of the main things I had to learn was how to secure it so people can&rsquo;t touch them. One of the main ways to do that is by hardening ssh.</p> +<p>Here I will name a couple of settings and best practices to make sure your ssh is as secure as possible.</p> +<hr> +<h2 id="use-key-pairs">Use key pairs</h2> +<p>One of the main practice to secure ssh is by using public/private ssh key pair and making ssh only allow connection with them, disabling password login.</p> +<p>First you need to generate a key pair by running the commmand <code>ssh-keygen</code>.</p> +<p>After generating the key and the command <code>ssh-copy-id ~/.ssh/key_name user@host</code> to copy the key to the server.</p> +<p>Connection to the server now it will ask you for the ssh key password if you set one, if you didn&rsquo;t then it will just directly connect it.</p> +<p>While you are connected to the server now, I would recommend you to change next settings to the values I recommend to make sure you can only connect to the server with ssh key pairs already on the server. Make sure to uncommmend the values in your config, and change like I did in my examples.</p> +<blockquote> +<p>/etc/ssh/sshd_config</p> +</blockquote> +<pre tabindex="0"><code class="language-conf" data-lang="conf">PubkeyAuthentication yes + +PasswordAuthentication no +PermitEmptyPasswords no +</code></pre><p>Restart your sshd service, with <code>systemctl restart sshd.service</code>.</p> +<h2 id="disable-root-user-logins">Disable root user logins</h2> +<p>Next most common way to secure ssh is by not using a root account to connect, so even if somebody manages to connect they don&rsquo;t get root user access.</p> +<p>After creating a new user ( make sure to add it to sudo/wheel group also ), make sure to copy the file located in <code>/root/.ssh/authorized_keys</code> to your new users directory in path <code>/home/user/.ssh/authorized_keys</code></p> +<p>I would reccommend at this point to try and connecting to the different user on the server to make sure the ssh keys were copied correctly. ( example <code>ssh new-user@host</code> )</p> +<p>After that, disable root user login and only allow connecting to ssh with the new user.</p> +<blockquote> +<p>/etc/ssh/sshd_config</p> +</blockquote> +<pre tabindex="0"><code class="language-conf" data-lang="conf">PermitRootLogin no +AllowUsers new-user +</code></pre><p>Restart your sshd service.</p> +<h2 id="only-allow-connection-from-specific-ip">Only allow connection from specific ip</h2> +<p>Next best way to secure ssh is to only allow connection from specific ip, preferably vpn.</p> +<p>Main way I do it is using wireguard. I set it up using the landchad <a href="https://landchad.net/wireguard">guide</a>.</p> +<p>Then in your sshd config you can make it so that ssh will only accept connection to the user with only the current using syntax.</p> +<pre tabindex="0"><code class="language-conf" data-lang="conf">AllowUsers new-user@172.16.0.2 +</code></pre><p>You can use the ip for the connection you use to setup the peer in the wireguard setup guide, which in landchad&rsquo;s guide is <code>172.16.0.2</code>. Or from another server by using the ip of the server you connect with wireguard to.</p> +<p>Make sure to restart sshd and test out in another terminal window whether you can only connect with the wireguard connection to the server ( Don&rsquo;t close or exit the current ssh connection before making sure it all work&rsquo;s ).</p> +<h2 id="general-settings">General settings</h2> +<p>There are some more settings that can be changed and I will name them now.</p> +<pre tabindex="0"><code class="language-conf" data-lang="conf"># Port change to allow connection from only that port, to connect use &#34;ssh new-user@host -p port&#34; +Port 4893 + +# Allow connection only from ipv4 +AddressFamily inet + +# Limit to only 3 connection tries +MaxAuthTries 3 + +# Disable pam +UsePAM no + +# Disable tcp and x11 forwarding +AllowTcpForwarding no +X11Forwarding no +</code></pre><p>If you by chance need tcp or x11 forwarding, enable it only for your user using this syntax:</p> +<pre tabindex="0"><code class="language-conf" data-lang="conf">Match User new-user + AllowTcpForwarding yes + X11Forwarding yes +</code></pre><hr> +<p>With this I have covered the most basic, but at the same best practices to secure your server ssh to not get uninvited people connecting to your servers.</p> + + Setup Traefik https://cronyakatsuki.xyz/blog/setup-traefik/ diff --git a/public/blog/securing-ssh/index.html b/public/blog/securing-ssh/index.html new file mode 100644 index 0000000..6679f8c --- /dev/null +++ b/public/blog/securing-ssh/index.html @@ -0,0 +1,165 @@ + + + + + + + + + + + + Securing Ssh - Crony Akatsuki + + + + + + + + + + + + +
    +

    Crony Akatsuki

    + +
    + + +
    +
    + +

    Securing Ssh

    + + + +
    +

    04-04-2024

    + + +
    +
    + +

    As someone who has a couple of servers out in the open web, one of the main things I had to learn was how to secure it so people can’t touch them. One of the main ways to do that is by hardening ssh.

    +

    Here I will name a couple of settings and best practices to make sure your ssh is as secure as possible.

    +
    +

    Use key pairs

    +

    One of the main practice to secure ssh is by using public/private ssh key pair and making ssh only allow connection with them, disabling password login.

    +

    First you need to generate a key pair by running the commmand ssh-keygen.

    +

    After generating the key and the command ssh-copy-id ~/.ssh/key_name user@host to copy the key to the server.

    +

    Connection to the server now it will ask you for the ssh key password if you set one, if you didn’t then it will just directly connect it.

    +

    While you are connected to the server now, I would recommend you to change next settings to the values I recommend to make sure you can only connect to the server with ssh key pairs already on the server. Make sure to uncommmend the values in your config, and change like I did in my examples.

    +
    +

    /etc/ssh/sshd_config

    +
    +
    PubkeyAuthentication yes
    +
    +PasswordAuthentication no
    +PermitEmptyPasswords no
    +

    Restart your sshd service, with systemctl restart sshd.service.

    +

    Disable root user logins

    +

    Next most common way to secure ssh is by not using a root account to connect, so even if somebody manages to connect they don’t get root user access.

    +

    After creating a new user ( make sure to add it to sudo/wheel group also ), make sure to copy the file located in /root/.ssh/authorized_keys to your new users directory in path /home/user/.ssh/authorized_keys

    +

    I would reccommend at this point to try and connecting to the different user on the server to make sure the ssh keys were copied correctly. ( example ssh new-user@host )

    +

    After that, disable root user login and only allow connecting to ssh with the new user.

    +
    +

    /etc/ssh/sshd_config

    +
    +
    PermitRootLogin no
    +AllowUsers new-user
    +

    Restart your sshd service.

    +

    Only allow connection from specific ip

    +

    Next best way to secure ssh is to only allow connection from specific ip, preferably vpn.

    +

    Main way I do it is using wireguard. I set it up using the landchad guide.

    +

    Then in your sshd config you can make it so that ssh will only accept connection to the user with only the current using syntax.

    +
    AllowUsers new-user@172.16.0.2
    +

    You can use the ip for the connection you use to setup the peer in the wireguard setup guide, which in landchad’s guide is 172.16.0.2. Or from another server by using the ip of the server you connect with wireguard to.

    +

    Make sure to restart sshd and test out in another terminal window whether you can only connect with the wireguard connection to the server ( Don’t close or exit the current ssh connection before making sure it all work’s ).

    +

    General settings

    +

    There are some more settings that can be changed and I will name them now.

    +
    # Port change to allow connection from only that port, to connect use "ssh new-user@host -p port"
    +Port 4893
    +
    +# Allow connection only from ipv4
    +AddressFamily inet
    +
    +# Limit to only 3 connection tries
    +MaxAuthTries 3
    +
    +# Disable pam
    +UsePAM no
    +
    +# Disable tcp and x11 forwarding
    +AllowTcpForwarding no
    +X11Forwarding no
    +

    If you by chance need tcp or x11 forwarding, enable it only for your user using this syntax:

    +
    Match User new-user
    +    AllowTcpForwarding yes
    +    X11Forwarding yes
    +

    +

    With this I have covered the most basic, but at the same best practices to secure your server ssh to not get uninvited people connecting to your servers.

    +
    + + + + + diff --git a/public/index.html b/public/index.html index 1b48a96..2d345b1 100644 --- a/public/index.html +++ b/public/index.html @@ -2,7 +2,7 @@ - + @@ -63,7 +63,8 @@

    Currently mostly playing games and learning about nix and nixos, sometimes I - throw in a movie or a tv show in the mix tho. + throw in a movie or a tv show in the mix tho. Here is my nixos + config.

    I'm an cli only person except when browsing the web or browsing the web, in diff --git a/public/sitemap.xml b/public/sitemap.xml index 5986ff2..6cce6b9 100644 --- a/public/sitemap.xml +++ b/public/sitemap.xml @@ -3,10 +3,13 @@ xmlns:xhtml="http://www.w3.org/1999/xhtml"> https://cronyakatsuki.xyz/blog/ - 2024-01-19T09:33:47+01:00 + 2024-04-04T20:44:10+02:00 https://cronyakatsuki.xyz/ - 2024-01-19T09:33:47+01:00 + 2024-04-04T20:44:10+02:00 + + https://cronyakatsuki.xyz/blog/securing-ssh/ + 2024-04-04T20:44:10+02:00 https://cronyakatsuki.xyz/blog/setup-traefik/ 2024-01-19T09:33:47+01:00