Yuav ua li cas rau nruab thiab configure SSH neeg rau zaub mov rau Debian Linux?
Txhim kho thiab soj ntsuam cov SSH neeg rau zaub mov
You will need to be root to do the following…
su
-
Nruab SSH neeg rau zaub mov
apt install openssh-server
-
Kos yog hais tias tus neeg rau zaub mov kev tshwm sim. Qhov no qhia lub nruab mus zoo.
ps -A | grep sshdTso zis (los yog zoo ib yam li):
1753 ? 00:00:00 sshd -
Nruab SSH Client mus xyuas lub SSH neeg rau zaub mov kev twb kev txuas
apt install openssh-clientTxuas mus rau localhost mus ntsuam xyuas kev twb kev txuas
ssh localhostTsis tas li ntawd tus ID nkag mus nrog cov interface IP chaw nyob
Tau IP chaw nyob
ip addrSSH mus rau lub ip chaw nyob
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
-
Kos yog .ssh tshwm sim
ls -a
-
Yog hais tias .ssh tsis muaj nyob, tsim nws
mkdir .ssh
-
Teem lub nplaub tshev tso cai rau 700
chmod 700 .ssh
-
Create the authorized_keys file
touch ./.ssh/authorized_keys
-
Change permission on the authorized_keys file to 600
chmod 600 ./.ssh/authorized_keys
-
Open the authorized_keys file
nano ./.ssh/authorized_keys
-
Paste your public key into the file
You can get your public key from the SSH client. If the client is Windows 10 then it will be in the
%USERPROFILE%/.ssh/id_rsa.pubntaub ntawv. If the client is Debian then the public key is~/.ssh/id_rsa.pub.If your public key does not exist, generate it on the client machine
ssh-keygen -t rsa -C "email@domain.com"
-
Change to root user
su -
Configure your SSH server to accept only public key logins and prevent login for root
nano /etc/ssh/sshd_configUncomment and/or edit the following lines
PermitRootLogin no
StrictModes yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
PasswordAuthentication no
-
Restart the sshd service
service sshd restart
-
Try logging in as root from your SSH client using password
ssh root@{ssh server ip address}Tso zis:
Permission denied (publickey). -
Try logging in as username from your SSH client using password
ssh username@{ssh server ip address}Tso zis:
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_rsaTso zis:
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.
