documentation:ssh
Differences
This shows you the differences between two versions of the page.
| documentation:ssh [2020/02/01 12:35] – external edit 127.0.0.1 | documentation:ssh [2020/02/02 15:16] (current) – removed lucid | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Setting Up SSH Securely ====== | ||
| - | While the SSH protocol might be secure on its own, there are a few things that can be done to ensure that security. One of the main methods for attacking SSH is a brute-force attack. This method only works if port is known by the attacker, typically gleaned from a port scan. It is typical for scanner bots to only scan for certain ports being open such at the default for SSH which is port 22. The attacker might also employ a different approach which is port scanning, typically only the first 1000 or so ports since scanning all the ports can take a rather long time if you wish to scan multiple IPs. Therefore one of the simplest methods for mitigating port scanning is to change your SSH port to something over 40000, well outside the range of what would be reasonable to scan for most bots. Although changing the port number may help the best way to prevent intrusions is to make SSH only accessible with a key pair. This article will explain both methods, the first one is much easier but far less secure, the second should be the default for connecting over SSH since the attack surface on SSH is realistically removed. | ||
| - | |||
| - | This tutorial is targeted towards Ubuntu 16.04 LTS, other distros maybe have slight nuances but the process should remain the same. | ||
| - | |||
| - | For setting up an sftp server with secure, separated users shares, follow this guide: | ||
| - | [[documentation: | ||
| - | |||
| - | ====== Process ====== | ||
| - | ==== Port Changing ==== | ||
| - | Install and enable ssh if not installed already. | ||
| - | < | ||
| - | sudo apt install ssh | ||
| - | sudo systemctl enable ssh | ||
| - | </ | ||
| - | Configure ssh to run on a different port | ||
| - | < | ||
| - | nano / | ||
| - | </ | ||
| - | Change the number after Port on line five to something over 40000. | ||
| - | Example: | ||
| - | < | ||
| - | # What ports, IPs and protocols we listen for | ||
| - | Port 22 <= Change this line | ||
| - | # Use these options to restrict... | ||
| - | </ | ||
| - | |||
| - | ==== Setup Key ==== | ||
| - | |||
| - | Make the key on a seperate machine that the one you wish to connect to. It will ask you to name the key and enter a passphrase if you choose to do so. | ||
| - | < | ||
| - | ssh-keygen -t rsa -b 4096 | ||
| - | </ | ||
| - | |||
| - | Copy the key to the server. If you have already changed the default ssh port then you will need to specify it. | ||
| - | < | ||
| - | ssh-copy-id < | ||
| - | </ | ||
| - | |||
| - | More information and troubleshooting options can be found [[https:// | ||
| - | |||
| - | ===== SFTP ====== | ||
| - | ==== Connecting to a server ==== | ||
| - | Example: | ||
| - | < | ||
| - | $ sftp USERNAME@x.x.x.x:/ | ||
| - | </ | ||
| - | |||
| - | The syntax for denoting the port number for sftp is not the same as for ssh for some reason | ||
| - | |||
| - | < | ||
| - | $ ssh USERNAME@x.x.x.x -p PORT | ||
| - | $ sftp -P PORT USERNAME@x.x.x.x:/ | ||
| - | </ | ||
| - | |||
| - | ===== Mounting an SFTP Share in fstab ===== | ||
| - | To add an sftp in fstab and have it automount at boot is a problem I have yet to solve while only changing fstab mount options. The sample fstab entry will work fine when "$ sudo mount -a" is run. To do this you will first need to generate and copy an ssh key to the server you are trying to connect to, outlined in the above sections. Then all you need to do is add the folling line to your /etc/fstab. | ||
| - | < | ||
| - | USERNAME@x.x.x.x:/ | ||
| - | </ | ||
| - | |||
| - | ===== SSH Keys ===== | ||
| - | |||
| - | On host machine, make a passphrase if you wish. | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | |||
| - | On server after logging in | ||
| - | < | ||
| - | Modify the following line and test | ||
| - | < | ||
documentation/ssh.1580560512.txt.gz · Last modified: 2021/06/18 16:36 (external edit)