Si për të instaluar dhe konfiguruar server SSH për Debian Linux?

Instalimi dhe testimi Server SSH

You will need to be root to do the following…

su

  1. Install SSH Server

    apt install openssh-server
     

  2. Kontrolloni nëse procesi server ekziston. Kjo tregon instaloni shkoi mirë.

    ps -A | grep sshd

    prodhim (ose të ngjashme): 1753 ? 00:00:00 sshd

     

  3. Install klient SSH për të kontrolluar lidhjen SSH Server

    apt install openssh-client

    Lidhu tek pritësi lokal për të testuar lidhjen

    ssh localhost

    Gjithashtu identifikoheni me ndërfaqe adresë IP

    Get IP Address

    ip addr

    SSH në adresën IP

    ssh {ipaddress here}
     

Securing the SSH Server

It is a good idea to secure the SSH server by disallowing root to login and configuring login only by public key i.e. login using passwords is not allowed

Ensure to execute the following commands as your user and not as root

  1. Navigate to the user home directory

    cd
     

  2. Kontrolloni nëse ekziston .ssh

    ls -a
     

  3. Nëse .ssh nuk ekziston, krijuar atë

    mkdir .ssh
     

  4. Set leje dosje për 700

    chmod 700 .ssh
     

  5. Krijo authorized_keys file

    touch ./.ssh/authorized_keys
     

  6. Ndryshimi leje në authorized_keys dosjen në 600

    chmod 600 ./.ssh/authorized_keys
     

  7. Hapni authorized_keys file

    nano ./.ssh/authorized_keys
     

  8. Paste kyç tuaj publik në dosjen

    Ju mund të merrni kyç tuaj publik nga klienti SSH. Nëse klienti është Windows 10 atëherë ajo do të jetë në %USERPROFILE%/.ssh/id_rsa.pub skedar. Nëse klienti është Debian atëherë çelësi publik është ~/.ssh/id_rsa.pub.

    Nëse çelësi juaj publike nuk ekziston, gjenerojë atë në makinë klientit

    ssh-keygen -t rsa -C "email@domain.com"
     

  9. Change to root user

    su

  10. Konfiguro serverin tuaj SSH për të pranuar vetëm hyrje kryesore publike dhe për të parandaluar login për rrënjë

    nano /etc/ssh/sshd_config

    Uncomment and/or edit the following lines

    PermitRootLogin no
    StrictModes yes
    PubkeyAuthentication yes
    AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
    PasswordAuthentication no
     

  11. Restart the sshd service

    service sshd restart
     

  12. Try logging in as root from your SSH client using password

    ssh root@{ssh server ip address}

    prodhim: Permission denied (publickey).

     

  13. Try logging in as username from your SSH client using password

    ssh username@{ssh server ip address}

    prodhim: Permission denied (publickey).

     

  14. Try logging in as root from your SSH client using the public key

    ssh root@{ssh server ip address} -i .ssh/id_rsa

    prodhim: Permission denied (publickey).

     

  15. Identifikohu si emrin nga klientit tuaj SSH duke përdorur çelësin publik

    ssh username@{ssh server ip address} -i .ssh/id_rsa
     

Nëse klienti juaj SSH ka një adresë statike IP, atëherë ju mund të dëshirojnë të marrin në konsideratë vetëm IP adresën tuaj mund të hyni brënda për të server SSH.