Paano i-install at i-configure ang SSH server sa Debian Linux?
Pag-install at pagsubok ng SSH Server
You will need to be root to do the following…
su
-
I-install SSH Server
apt install openssh-server
-
Suriin kung ang proseso ng server ay umiiral. Ito ay nagpapahiwatig ng install nagpunta maayos.
ps -A | grep sshdoutput (o katulad):
1753 ? 00:00:00 sshd -
I-install SSH Client upang suriin ang koneksyon SSH Server
apt install openssh-clientKumonekta sa localhost upang masubukan ang koneksyon
ssh localhostGayundin mag-login gamit ang interface IP address
Kunin ang IP Address
ip addrSSH sa ip address
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
-
Navigate to the user home directory
cd
-
Suriin kung Ssh umiiral
ls -a
-
Kung Ssh ay hindi umiiral, Lumikha ng ito
mkdir .ssh
-
I-set ang folder ng pahintulot na 700
chmod 700 .ssh
-
Lumikha ng authorized_keys file
touch ./.ssh/authorized_keys
-
Baguhin ang pahintulot sa authorized_keys file upang 600
chmod 600 ./.ssh/authorized_keys
-
Buksan ang authorized_keys file
nano ./.ssh/authorized_keys
-
I-paste ang iyong mga pampublikong key sa file
Maaari mong makuha ang iyong mga pampublikong susi mula sa SSH client. Kung ang client ay Windows 10 pagkatapos ito ay magiging sa
%USERPROFILE%/.ssh/id_rsa.pubtalaksan. Kung ang client ay Debian pagkatapos ay ang public key ay~/.ssh/id_rsa.pub.Kung ang iyong mga pampublikong key ay hindi umiiral, bumuo ng mga ito sa client machine
ssh-keygen -t rsa -C "email@domain.com"
-
Change to root user
su -
Isaayos ang iyong SSH server na tanggapin lamang ang public key login at maiwasan ang pag-login para sa root
nano /etc/ssh/sshd_configUncomment at / o i-edit ang mga sumusunod na mga linya
PermitRootLogin no
StrictModes yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
PasswordAuthentication no
-
I-restart ang sshd service
service sshd restart
-
Try logging in as root from your SSH client using password
ssh root@{ssh server ip address}output:
Permission denied (publickey). -
Subukang mag-log in bilang username mula sa iyong SSH client na gumagamit ng password
ssh username@{ssh server ip address}output:
Permission denied (publickey). -
Try logging in as root from your SSH client using the public key
ssh root@{ssh server ip address} -i .ssh/id_rsaoutput:
Permission denied (publickey). -
Log in as username from your SSH client using the public key
ssh username@{ssh server ip address} -i .ssh/id_rsa
If your SSH client has a static IP address then you may want to consider only your IP address can login to the SSH server.
