Configure SSH with key base authencation on CentOS7 (Hướng dẫn cấu hình SSH xác thực bằng key)

6 253 0
Configure SSH with key base authencation on CentOS7 (Hướng dẫn cấu hình SSH xác thực bằng key)

Đang tải... (xem toàn văn)

Thông tin tài liệu

Cấu hình SSH chứng thực dựa trên key trên hệ điều hành CentOS 7.Cấu hình SSH chứng thực dựa trên key trên hệ điều hành CentOS 7Cấu hình SSH chứng thực dựa trên key trên hệ điều hành CentOS 7Cấu hình SSH chứng thực dựa trên key trên hệ điều hành CentOS 7Cấu hình SSH chứng thực dựa trên key trên hệ điều hành CentOS 7

CẤU HÌNH SSH KEY-BASED AUTHENTICATION TRÊN CENTOS Link hướng dẫn: https://www.ostechnix.com/configure-ssh-key-based-authentication-linux/ SSH Server details:    OS : CentOS 64-bit IP address : 192.168.28.149/24 SSH client details:   OS : Ubuntu 16.04 LTS 64-bit IP address : 192.168.28.139/24 Lưu ý quan trọng: Không tạo cặp khóa với quyền root, có root sử dụng khóa Tạo cặp khóa với quyền user bình thường TẠO KHĨA TẠI CLIENT Tại máy client: tuananh@ubuntu:~$ ssh-keygen Generating public/private rsa key pair Enter file in which to save the key (/home/tuananh/.ssh/id_rsa): Created directory '/home/tuananh/.ssh' Enter passphrase (empty for no passphrase): 123456 Enter same passphrase again: 123456 Your identification has been saved in /home/tuananh/.ssh/id_rsa Your public key has been saved in /home/tuananh/.ssh/id_rsa.pub The key fingerprint is: SHA256:cwCpDV8guJqd3kEXAEhPK+7Nn8ckKwrBGwSN3STGCQs tuananh@ubuntu The key's randomart image is: + -[RSA 2048] + |EO+B+.oo | |=oO.+.o | |.o + = o | |+ o o + | |.B o S | |+.B o | |.+ + = | | o o | | .o | + [SHA256] -+ Trong trường hợp bạn tạo cặp khóa, bạn thấy thơng báo sau Chỉ cần gõ "y" để tạo ghi đè lên khoá /home/username/.ssh/id_rsa already exists Overwrite (y/n)? Khóa tạo thành cơng client, copy public key cho SSH lệnh: tuananh@ubuntu:~$ ssh-copy-id root@192.168.28.149 The authenticity of host '192.168.28.149(192.168.28.149)' can't be established ECDSA key fingerprint is SHA256:0UYB6aehcNKmgtBWj6KMpW2sF8582kam9M4PvqT7NhI Are you sure you want to continue connecting (yes/no)? yes /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: key(s) remain to be installed if you are prompted now it is to install the new keys root@192.168.28.149's password: mật user root Server Number of key(s) added: Now try logging into the machine, with: "ssh 'root@192.168.28.149'" and check to make sure that only the key(s) you wanted were added hoặc: cat ~/.ssh/id_rsa.pub | ssh root@Server_IP_Address "cat >> ~/.ssh/authorized_keys" CẤU HÌNH TẠI SERVER Vì cấu hình SSH Key-base Authentication nên bỏ chế độ Password-based Authentication Sửa file cấu hình SSH Server: vi /etc/ssh/sshd_config Sửa dòng sau: PasswordAuthentication no PubkeyAuthentication yes Khởi động lại dịch vụ SSH server: service sshd restart Kết nối tới SSH Server từ client ssh root@192.168.28.149 123456 (mật ta phát sinh khóa) Thử SSH vào SSH Server với user3 ssh user3@192.168.28.149 Lý không SSH vào user3 được: SSH Server chế độ Key-base Authentication, không cho phép đăng nhập Password Và user3 (trên server) chưa cấu hình để chấp nhận public key từ tuananh@ubuntu Tạo thêm khóa để đăng nhập Server user khác Trên server: Add The New User if not exist useradd user3 passwd user3 Create Directories and Files mkdir -p /home/user3/.ssh touch /home/user3/.ssh/authorized_keys Set Proper Permissions chown user3:user3 /home/user3/.ssh chown user3:user3 /home/user3/.ssh/authorized_keys chmod 700 /home/user3/.ssh chmod 600 /home/user3/.ssh/authorized_keys Copy public key từ client : Setup SSH Keys for myuser echo "ssh-rsa " >> /home/user3/.ssh/authorized_keys service sshd restart Tại client thành công: ... hình SSH Key-base Authentication nên bỏ chế độ Password-based Authentication Sửa file cấu hình SSH Server: vi /etc /ssh/ sshd_config Sửa dòng sau: PasswordAuthentication no PubkeyAuthentication yes... vụ SSH server: service sshd restart Kết nối tới SSH Server từ client ssh root@192.168.28.149 123456 (mật ta phát sinh khóa) Thử SSH vào SSH Server với user3 ssh user3@192.168.28.149 Lý không SSH. .. the machine, with: "ssh 'root@192.168.28.149'" and check to make sure that only the key(s) you wanted were added hoặc: cat ~/ .ssh/ id_rsa.pub | ssh root@Server_IP_Address "cat >> ~/ .ssh/ authorized_keys"

Ngày đăng: 26/10/2018, 19:13

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan