كيفية استخدام مفتاح (SSH) إس إس إتش خاص

كيفية استخدام مفتاح (SSH) سسش خاص

ما هو المفتاح الخاص ؟

حتى كلمات المرور الأكثر تعقيدًا لا يمكن أن تتطابق مع قوة التشفير للمفاتيح الخاصة. مع تعمل المفاتيح الخاصة على تحسين الأمان بشكل كبير من خلال تخفيف عبء تذكر كلمات المرور المعقدة (أو الأسوأ من ذلك، كتابتها).

دعونا أولاً نفتح نافدة الأوامر وننشئ مفتاحًا خاصًا.

الخطوة 1: تحقق لمعرفة ما إذا كان لديك فعلًا مفتاح SSH.

$ ls ~/.ssh
Output:
ubuntu@ubuntu2004:~$ ls ~/.ssh
known_hosts

الخطوة 2: إنشاء مفتاح SSH.

$ ssh-keygen
Output:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/francxpt/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/francxpt/.ssh/id_rsa
Your public key has been saved in /home/francxpt/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:Wp/XRdw1LwLAvl5CF5upDIciAQhfnNNrLFUf/OiBqLs francxpt@LAPTOP-TCSB0JE9
The key's randomart image is:
+---[RSA 3072]----+
|=. ..o oooo    ..|
|....+ o ..oo   .=|
|  .. + = ..B. . =|
|  . o B = B .. o |
|   . = =S= .    .|
|    .  o=.o. . . |
|     ... oo . .  |
|    .   .  .     |
|    E.           |
+----[SHA256]-----+

سيطلب منك اسم ملف. بشكل افتراضي ، يتم تخزين أزواج مفاتيح ssh على هيئة id_rsa و id_rsa.pub للمفتاح الخاص والمفتاح العام ، على التوالي.

Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):

لاستخدام اسم الملف الافتراضي ، اضغط على ENTER وتابع.

في الجزء التالي ، أدخل عبارة مرور لتأمين أزواج المفاتيح. يمكنك تخطي هذا بالضغط على ENTER.

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

الخطوة 3: نسخ المفتاح العام إلى المضيف البعيد.

$ ls ~/.ssh
Output:
ubuntu@ubuntu2004:~$ ls ~/.ssh
id_rsa  id_rsa.pub  known_hosts

لاستخدام زوج مفاتيح SSH الذي أنشأته، يجب علينا أولاً نسخ المفتاح العام للخادم البعيد. لحسن الحظ، يتضمن OpenSSH وظيفة

ssh-copy-id للقيام بذلك.

$ ssh-copy-id remote_server_user@remote_server_ip
Output:
ubuntu@ubuntu2004:$ ssh-copy-id [email protected] 
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ubuntu/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed 
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys! 
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh [email protected]"
and check to make sure that only the key(s) you wanted were added.

الخطوة 4: (SSH) إس إس إتش باستخدام المفتاح الخاص.

$ ssh remote_server_user@remote_server_ip
Output:
ubuntu@ubuntu2004:$ ssh [email protected]
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
7 updates can be applied immediately.
7 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
This message is shown once a day. To disable it please create the
/home/ubuntu/.hushlogin file.
ubuntu@ubuntuserver2204:$

لقد نجحت الآن في استخدام المصادقة القائمة على المفتاح SSH. من خلال إلغاء تسجيل الدخول بكلمة مرور، يمكنك توفير درجة إضافية من الحماية.

استنتاج

أظهر لك هذا البرنامج التعليمي كيفية إنشاء أزواج مفاتيح SSH ونسخ مفاتيح المضيفين عن بُعد. تسمح لك الخطوات المذكورة أعلاه بمصادقة جلسات SSH إس إس إتش دون استخدام كلمة مرور. علاوة على ذلك، يمكنك التحكم في العديد من الخوادم في نفس الوقت باستخدام زوج مفاتيح واحد.

LEAVE A COMMENT