create account

Setting Up A Linux VPS Securely (Pt.2) by krnel

View this thread on: hive.blogpeakd.comecency.com
· @krnel · (edited)
$14.54
Setting Up A Linux VPS Securely (Pt.2)
Welcome back to the second part of securing your Linux Server. 

I won't talk about becoming a witness, or what a witness is, until I actually get to that part of the setup myself. This is about securing a server first. Sorry for mentioning the journey to becoming a witness too early, in the first post. So, I'm not becoming a witness yet. I'll mention it again when I actually get there ;)

As mentioned in [Part 1](https://steemit.com/witness-category/@krnel/setting-up-a-linux-vps-securely-pt-1-join-me-on-my-journey-to-become-a-witness), this part will deal with SSH keys to make your server even more secure.

### Let's get it on!

---
# Public and Private Keys for SSH

Again being on Windows, grab the [PuttyGen.exe](https://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe) software. Click on that link and it will download. Open the program, nothing is installed.

<center><img src="http://www.steemimg.com/images/2016/11/26/generate-keyed3d7.png" alt="generate-keyed3d7.png" border="0"></center>

Click on ```Generate```, and move your mouse around the blank area under the status/progress bar. You will see the bar fill up as you move your mouse around. Keep going until the key is generated.

After that, you will get your keys. Copy the "Public key for pasting" into a file, call it pub_key.txt. Next, put in a "Key passphrase" if you want some extra security, but if you're the only one connecting to your server then it's not that big of a deal. Then click "Save public key", call it "pub_key". Then click "Save private key", and save it as "private.ppk".

<center><img src="http://www.steemimg.com/images/2016/11/26/generate-save724f2.png" alt="generate-save724f2.png" border="0"></center>

So if you saved them like I named them, you will have three files:

> pubkey.txt
> pub_key
> private.ppk

---
# Install public key on server

Now that the keys have been generated on your local computer, it's time to upload the public key to the server so you can connect with it.

Open putty, load the profile, and Open the connection. Put your user password, and login. Remember, we're no longer logging in as root.

Do the follow commands

1. ```mkdir ~/.ssh```
Make a hidden user directory

2. ```chmod 700 ~/.ssh```
Modify the folder access

3. ```cd ~/.ssh```
Go into the folder

4. ```nano authorized_keys```
Create a file for the key, it has to be this name

5. Open "public_key.txt" from before and copy it's contents. Then paste those contents into putty that has the file "authorized_keys" open. Save and close the file: ctrl+o or just ctrl+x and save the file before exiting.

6. ```chmod 600 authorized_keys```
Set file access on thr public key so no other users can access it, except for root

<center><img src="http://www.steemimg.com/images/2016/11/26/ssh-dir962eb.png" alt="ssh-dir962eb.png" border="0"></center>

---
# Disable password logins

Open the sshd_config file:

```sudo nano /etc/ssh/sshd_config```

Scroll down with the arrow key, or hit Page Down twice, to find ```PasswordAuthentication yes```

Change the "yes" to "no":

```PasswordAuthentication no```

Then restart the service:

```sudo service ssh restart```

<center><img src="http://www.steemimg.com/images/2016/11/27/ssh-password-yes4cfc3.png" alt="ssh-password-yes4cfc3.png" border="0"></center>

# Test SSH login with a key, instead of password

Open putty, and load your profile. Go to the left panel section, and go to the "Auth" section shown here:

<center><img src="http://www.steemimg.com/images/2016/11/26/putty-authfb735.png" alt="putty-authfb735.png" border="0"></center>

Next, click "Browse" to find the "private.ppk" file we saved earlier.

<center><img src="http://www.steemimg.com/images/2016/11/27/putty-private-leyd7a70.png" alt="putty-private-leyd7a70.png" border="0"></center>

The last thing to do is "Save" your profile in putty so that you don't need to do this again. Go to the top to "Session" and you can save again.

<center><img src="http://www.steemimg.com/images/2016/11/27/putty-savec88d4.png" alt="putty-savec88d4.png" border="0"></center>

And then just click "Open" to connect with your new SSH key.

If you are prompted to accept a key, click "Yes".

If you set a passphrase for your key earlier, then this when time you need to use it. If you didn't put a passphrase, then you login without using a password, and it's still more secure being it uses private-public keys.

<center><img src="http://www.steemimg.com/images/2016/11/27/rsa-prompt88d00.png" alt="rsa-prompt88d00.png" border="0"></center>

# Remove IPv6 listening

Since no one really uses IPv6 yet, disable this and make one less thing your system is checking for.

```AddressFamily inet``` needs to be added.

You can add this manually to the end of the sshd_config file @ ```nano /etc/ssh/sshd_config```.

Or just run:

```echo 'AddressFamily inet' | sudo tee -a /etc/ssh/sshd_config```

If you ever need IPv6 SSH back, remove that line.

Finish with a restart of SSH:

```sudo service ssh restart```


---
# Done!

- [Setting Up A Linux VPS Securely (Pt.1)](https://steemit.com/witness-category/@krnel/setting-up-a-linux-vps-securely-pt-1-join-me-on-my-journey-to-become-a-witness)

---
#### Thank you for your time and attention! I appreciate the knowledge reaching more people. Take care. Peace.

<center><img src="http://i.imgur.com/LwhouOq.gif" /><img src="http://i.imgur.com/X7bllkJ.png" /> <strong>Payout Selected</strong></center>

---
If you appreciate and value the content, please consider:
Upvoting <img src="https://www.steemimg.com/images/2016/08/30/upvote91a69.png" alt="upvote91a69.png" /> ,&nbsp;&nbsp;&nbsp;&nbsp;Sharing <img src="https://www.steemimg.com/images/2016/08/30/share2195b.png" alt="share2195b.png" /> **and** &nbsp;&nbsp;Reblogging <img src="https://www.steemimg.com/images/2016/09/19/reblog33b5f.png" alt="reblog33b5f.png" /> **below**.

[![Follow](https://www.steemimg.com/images/2016/08/30/follow2be5e.png)](https://steemit.com/@krnel) me for more content to come!

---
@krnel
2016-11-28, 6:10am
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 208 others
properties (23)
authorkrnel
permlinksetting-up-a-linux-vps-securely-pt-2
categorycybersecurity
json_metadata{"tags":["cybersecurity","linux","vps","server","tutorial"],"users":["krnel"],"image":["http://www.steemimg.com/images/2016/11/26/generate-keyed3d7.png","http://www.steemimg.com/images/2016/11/26/generate-save724f2.png","http://www.steemimg.com/images/2016/11/26/ssh-dir962eb.png","http://www.steemimg.com/images/2016/11/27/ssh-password-yes4cfc3.png","http://www.steemimg.com/images/2016/11/26/putty-authfb735.png","http://www.steemimg.com/images/2016/11/27/putty-private-leyd7a70.png","http://www.steemimg.com/images/2016/11/27/putty-savec88d4.png","http://www.steemimg.com/images/2016/11/27/rsa-prompt88d00.png","http://i.imgur.com/LwhouOq.gif","http://i.imgur.com/X7bllkJ.png","https://www.steemimg.com/images/2016/08/30/upvote91a69.png","https://www.steemimg.com/images/2016/08/30/share2195b.png","https://www.steemimg.com/images/2016/09/19/reblog33b5f.png","https://www.steemimg.com/images/2016/08/30/follow2be5e.png"],"links":["https://steemit.com/witness-category/@krnel/setting-up-a-linux-vps-securely-pt-1-join-me-on-my-journey-to-become-a-witness","https://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe","https://steemit.com/@krnel"],"app":"steemit/0.1","format":"markdown"}
created2016-11-28 11:10:48
last_update2016-11-28 12:16:15
depth0
children5
last_payout2016-12-29 11:44:30
cashout_time1969-12-31 23:59:59
total_payout_value13.715 HBD
curator_payout_value0.827 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,029
author_reputation1,343,547,270,297,082
root_title"Setting Up A Linux VPS Securely (Pt.2)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id1,863,419
net_rshares44,702,928,022,501
author_curate_reward""
vote details (272)
@alexanderkroeger ·
Often I suspect this fetish of disabling IPv6 just hides the "we do not know how to secure IPv6". You give me inspiration to write a post like How to secure IPv6 in Linux....
properties (22)
authoralexanderkroeger
permlinkre-krnel-setting-up-a-linux-vps-securely-pt-2-20161128t141439456z
categorycybersecurity
json_metadata{"tags":"cybersecurity","custom":{"app":"esteem","version":"1.3.1","platform":"android"}}
created2016-11-28 13:14:36
last_update2016-11-28 13:14:36
depth1
children1
last_payout2016-12-29 11:44:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length174
author_reputation1,655,933,451,508
root_title"Setting Up A Linux VPS Securely (Pt.2)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,863,963
net_rshares0
@krnel · (edited)
Nice. I didn't know it was an issue. I thought it was disabled to make it one less thing to monitor for SSH.
properties (22)
authorkrnel
permlinkre-alexanderkroeger-re-krnel-setting-up-a-linux-vps-securely-pt-2-20161128t132353829z
categorycybersecurity
json_metadata{"tags":["cybersecurity"]}
created2016-11-28 13:23:54
last_update2016-11-28 13:24:06
depth2
children0
last_payout2016-12-29 11:44:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length108
author_reputation1,343,547,270,297,082
root_title"Setting Up A Linux VPS Securely (Pt.2)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,864,037
net_rshares0
@elmetro ·
Hi, I want to disable the password login but I have a messsage "No supported Authentification methods available (server sent: publickey)" when I test it.  I don't know if it's important but when I opened the config file, the line "PasswordAuthentication yes" was in comment so I had "#PasswordAuthentication yes" and I changed to "PasswordAuthentication no".
Do you have an idea of my issue? Thanks
properties (22)
authorelmetro
permlinkre-krnel-setting-up-a-linux-vps-securely-pt-2-20180404t231447730z
categorycybersecurity
json_metadata{"tags":["cybersecurity"],"app":"steemit/0.1"}
created2018-04-04 23:14:48
last_update2018-04-04 23:14:48
depth1
children0
last_payout2018-04-11 23:14:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length398
author_reputation2,378,652,793,261
root_title"Setting Up A Linux VPS Securely (Pt.2)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id48,379,813
net_rshares0
@nnnarvaez ·
Ok this is necro posting, but i do really suggest the clueless guys following this guide to first test they made the key thing work, then login and disable password logins... 

I gave this guide to a windows noob and he locked himself out 3 times before getting it right lol.


# FIRST: Test SSH login with a key, instead of password

# THEN: Disable password logins

Just common sense... i never tought i will be writting this in a guide to setup a node for blockchain...
properties (22)
authornnnarvaez
permlinkre-krnel-setting-up-a-linux-vps-securely-pt-2-20171004t150145787z
categorycybersecurity
json_metadata{"tags":["cybersecurity"],"app":"steemit/0.1"}
created2017-10-04 15:01:42
last_update2017-10-04 15:01:42
depth1
children0
last_payout2017-10-11 15:01:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length472
author_reputation64,435,481,297,270
root_title"Setting Up A Linux VPS Securely (Pt.2)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,771,792
net_rshares0
@screenname ·
Re: Setting Up A Linux VPS Securely (Pt.2)
<p>This post has been ranked within the top 80 most undervalued posts in the second half of Nov 28. We estimate that this post is undervalued by $7.57 as compared to a scenario in which every voter had an equal say.</p> 
<p>See the full rankings and details in <a href="https://steemit.com/curation/@screenname/the-daily-tribune-most-undervalued-posts-of-nov-28---part-ii">The Daily Tribune: Nov 28 - Part II</a>. You can also read about some of our methodology, data analysis and technical details in <a href="https://steemit.com/curation/@screenname/introducing-the-daily-tribune-most-undervalued-posts-of-nov-04---part-i">our initial post</a>.</p>
<p>If you are the author and would prefer not to receive these comments, simply reply "Stop" to this comment.</p>
👍  , , , , , ,
properties (23)
authorscreenname
permlinkre-setting-up-a-linux-vps-securely-pt-2-20161129t013336
categorycybersecurity
json_metadata"{"replyto": "@krnel/setting-up-a-linux-vps-securely-pt-2"}"
created2016-11-29 01:33:36
last_update2016-11-29 01:33:36
depth1
children0
last_payout2016-12-29 11:44:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length765
author_reputation46,276,338,038,330
root_title"Setting Up A Linux VPS Securely (Pt.2)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,869,009
net_rshares28,699,986,781
author_curate_reward""
vote details (7)