Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Lập Trình Bash

Thiết lập SSH Passwordless Login trên Linux trong 3 Bước Đơn Giản

SSH (Secure SHELL) là network protocol open-source và trusted nhất dùng để login remote servers để execute commands và programs. Cũng dùng transfer files giữa computers over network dùng secure copy (SCP) command và Rsync command.

[ You might also like: How to Secure and Harden OpenSSH Server ]

Bài viết hướng dẫn setup password-less login trên RHEL-based distributions (CentOS, Fedora, Rocky Linux & AlmaLinux) và Debian-based (Ubuntu & Mint) dùng ssh keys connect remote Linux servers không nhập password.

Dùng Password-less login với SSH keys tăng trust giữa 2 Linux servers cho easy file sync hoặc transfer.

Môi trường Setup của tôi
SSH Client : 192.168.0.12 ( Fedora 34 )
SSH Remote Host : 192.168.0.11 ( CentOS 8 )

Nếu deal với nhiều Linux remote servers, SSH Password-less login là một trong best ways automate tasks: automatic backups với scripts, sync files dùng SCP command, remote command execution.

[ You might also like: 25 Outstanding Backup Utilities for Linux Systems ]

Ví dụ này setup SSH password-less automatic login từ server 192.168.0.12 user tecmint đến 192.168.0.11 user sheena.

Bước 1: Tạo Authentication SSH-Keygen Keys trên (192.168.0.12)

Login server 192.168.0.12 với user tecmint generate key pair dùng command:

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/tecmint/.ssh/id_rsa): [Press enter key]
Created directory '/home/tecmint/.ssh'.
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Press enter key]
Your identification has been saved in /home/tecmint/.ssh/id_rsa.
Your public key has been saved in /home/tecmint/.ssh/id_rsa.pub.
The key fingerprint is:
5f:ad:40:00:8a:d1:9b:99:b3:b0:f8:08:99:c3:ed:d3 admin@wsxdn.com
The key's randomart image is:
+--[ RSA 2048]----+
| ..oooE.++|
| o. o.o |
| .. . |
| o . . o|
| S . . + |
| . . . o|
| . o o ..|
| + + |
| +. |
+-----------------+

Thiết lập SSH Passwordless Login trên Linux trong 3 Bước Đơn Giản

Bước 2: Upload SSH Key đến (192.168.0.11)

Dùng SSH từ server 192.168.0.12 upload public key mới (id_rsa.pub) lên server 192.168.0.11 dưới sheena's .ssh directory as filename authorized_keys.

$ ssh-copy-id admin@wsxdn.com

Bước 3: Test SSH Passwordless Login từ 192.168.0.12

Từ bây giờ bạn login vào 192.168.0.11 as sheena user từ server 192.168.0.12 as tecmint user không password.

$ ssh admin@wsxdn.com

Thiết lập SSH Passwordless Login trên Linux trong 3 Bước Đơn Giản

Bài viết đã hướng dẫn setup SSH Passwordless login dùng ssh key. Hy vọng process straightforward. Nếu có questions, post comment section below.