This is an old revision of the document!
Table of Contents
SSH Konfiguration
In diesem intrag soll es um die Grundlegende SSH Konfiguration gehen. Ausgegangen wird von der initialen Einrichtung eines Server wie hier beschrieben. Daher werden einige Abschnitte bei anderen Grundvorraussetzungen optional und können übersprungen werden.
Initial Connection
Wenn auf dem Server SSH eingerichtet ist, so werden die Stadard Einstellungen genutzt. Eine Verbindung kann daher mit dem folgenden Befehlt erfolgen:
ssh root@[IP-ADDRESS-OF-SERVER]
Es empfiehlt sich immer eine zusätzliche Verbindung aufzubauen, welche als Backup genutzt werden kann, wenn man sich bei Fehlern aus dem System aussperrt
Hat man nun zwei Terminals geöffnet, so kann man eines der Beiden dazu Nutzen die Konfiguration vorzunehmen.
Creating a user on a Linux machine and securing the connection with a private key
1. Log in to your Linux machine as a user with sudo privileges.
2. Run the `adduser` command to create a new user. Replace `USERNAME` with the desired username:
sudo adduser USERNAME
3. Follow the prompts to set the user's password and other information.
4. To allow the new user to log in using a private key, you will need to generate a public/private key pair. Run the following command to generate a new SSH key pair:
ssh-keygen -t rsa
5. Press `Enter` to accept the default location and file name for the key pair. You will be prompted to enter a passphrase for the key. It is highly recommended to use a strong, unique passphrase to protect your key.
6. Once the key pair is generated, you can view the public key by running the following command:
cat ~/.ssh/id_rsa.pub
7. Copy the output of the `cat` command, which is your public key.
8. Switch to the new user's account by running the following command:
mkdir ~/.ssh
10. Open a new file in the `.ssh` directory called `authorized_keys` using a text editor, such as `nano`:
nano ~/.ssh/authorized_keys
11. Paste the public key that you copied earlier into the `authorized_keys` file.
12. Save and close the file.
13. Set the correct permissions on the `.ssh` directory and `authorized_keys` file to protect them from unauthorized access:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
14. Exit the new user's account by running the `exit` command.
15. You should now be able to log in to the new user's account using the private key. To do so, run the following command from your local machine, replacing `USERNAME` with the username of the new user and `HOSTNAME` with the hostname or IP address of the Linux machine:
ssh -i ~/.ssh/id_rsa USERNAME@HOSTNAME
You will be prompted to enter the passphrase for the private key. Once you enter the correct passphrase, you should be logged in to the new user's account on the Linux machine.
sshd_config
Leider ist die Konfiguration je nach Betriebssystem anders untergebracht. Für gewöhnlich findet man diese jedoch unter /etc/ssh/sshd_config. Für die Bearbeitung wird Vim empfohlen. Auch ist durch den Ort, an welchem die Datei abgelegt ist notwendig, dass man die Bearbeitung mit sudo Rechten durchführt, da sonst das Speichern nicht erlaubt wird.
Das Konfigurationsfile hat viele Optionen und daher erhebt die Nachfolgende Liste keinen Anspruch auf vollständigkeit. Die Zeilen sind zudem meist auskommentiert, was durch ein # zu beginn der Zeile angedeutet wird. Dieses muss für das aktivieren der Option entsprechend entfernt werden.
Portgibt den Port an, auf welchem SSH lauscht. Es wird empfohlen diesen zu ändern, da Angreifer zu meiste den dafault Por 22 angreifenPermitRootLogingibt an, ob ein Login als root User möglich ist. Hier empfiehlt sich, die option auf no zu setzen, da der root User die einfachste Angriffsfläche bietet