Site update

This commit is contained in:
CronyAkatsuki 2024-04-04 21:35:06 +02:00
parent 0b4d2c5ac2
commit 8b550c4f94
4 changed files with 18 additions and 18 deletions

View file

@ -12,7 +12,7 @@
<item>
<title>Securing Ssh</title>
<title>Securing SSH</title>
<link>https://cronyakatsuki.xyz/blog/securing-ssh/</link>
<pubDate>04-04-2024</pubDate>
@ -23,9 +23,9 @@
&lt;h2 id=&#34;use-key-pairs&#34;&gt;Use key pairs&lt;/h2&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;First you need to generate a key pair by running the commmand &lt;code&gt;ssh-keygen&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;After generating the key and the command &lt;code&gt;ssh-copy-id ~/.ssh/key_name user@host&lt;/code&gt; to copy the key to the server.&lt;/p&gt;
&lt;p&gt;Connection to the server now it will ask you for the ssh key password if you set one, if you didn&amp;rsquo;t then it will just directly connect it.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;After generating the key run the command &lt;code&gt;ssh-copy-id ~/.ssh/key_name user@host&lt;/code&gt; to copy the key to the server.&lt;/p&gt;
&lt;p&gt;Connecting to the server now it will ask you for the ssh key password if you set one, if you didn&amp;rsquo;t then it will just directly connect it.&lt;/p&gt;
&lt;p&gt;While you are connected to the server now, I would 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 uncomment the values in your config, and change like I did in my examples.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;/etc/ssh/sshd_config&lt;/p&gt;
&lt;/blockquote&gt;
@ -48,7 +48,7 @@ AllowUsers new-user
&lt;h2 id=&#34;only-allow-connection-from-specific-ip&#34;&gt;Only allow connection from specific ip&lt;/h2&gt;
&lt;p&gt;Next best way to secure ssh is to only allow connection from specific ip, preferably vpn.&lt;/p&gt;
&lt;p&gt;Main way I do it is using wireguard. I set it up using the landchad &lt;a href=&#34;https://landchad.net/wireguard&#34;&gt;guide&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Then in your sshd config you can make it so that ssh will only accept connection to the user with only the specific up using this syntax.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-conf&#34; data-lang=&#34;conf&#34;&gt;AllowUsers new-user@172.16.0.2
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can use the ip for the connection you use to setup the peer in the wireguard setup guide, which in landchad&amp;rsquo;s guide is &lt;code&gt;172.16.0.2&lt;/code&gt;. Or from another server by using the ip of the server you connect with wireguard to.&lt;/p&gt;
&lt;p&gt;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&amp;rsquo;t close or exit the current ssh connection before making sure it all work&amp;rsquo;s ).&lt;/p&gt;