SSH (Secure Socket Shell) là một giao thức được sử dụng để đăng nhập một máy tính từ xa. Thông thường, người dùng hay sử dụng password để chứng thực khi SSH. Việc này rất có lợi cho hacker dễ dàng quét mật khẩu để truy cập vào hệ thống nếu người dùng đặt mật khẩu quá đơn giản. Vì thế hôm nay TEL4VN sẽ hướng dẫn mọi người cách ssh vào server linux dùng key, không cần password.
Trên CentOS:
OpenSSH đã được cài đặt mặc định khi cài đặt hệ điều hành CentOS lên server. Vì thế không cần cài đặt thêm package mới.
Trên Debian:
root@tel4vn:~# aptitude -y install ssh root@tel4vn:~# vi /etc/ssh/sshd_config
# line 28: change to no (prohibit root login # default setting “without-password” means that root login is permited but require key-pair authentication)
PermitRootLogin no root@tel4vn:~# systemctl restart ssh
root@tel4vn:~# ssh-keygen -t rsa
Generating public/private rsa key pair. Enter file in which to save the key (/home/root/.ssh/id_rsa): # Enter Enter passphrase (empty for no passphrase): # set passphrase (set no passphrase to Enter with empty) Enter same passphrase again: Your identification has been saved in /home/root/.ssh/id_rsa. Your public key has been saved in /home/root/.ssh/id_rsa.pub. The key fingerprint is: 30:ee:f0:47:38:9d:8a:24:5e:01:c8:13:df:15:40:b4 root@tel4vn The key’s randomart image is:
root@tel4vn:~# mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys root@tel4vn:~# chmod 600 ~/.ssh/authorized_keys root@tel4vn:~# cat /root/.ssh/id_rsa
Lưu lại nội dung của file về máy với đuôi .ppk. Ví dụ: key.ppk
root@tel4vn:~# vi /etc/ssh/sshd_config
# line 65: turn to [no]
PasswordAuthentication no
# line 69: make sure the value is [no]
ChallengeResponseAuthentication no
# line 96: make sure the value is [yes]
UsePAM yes root@tel4vn:~# systemctl restart sshd
# line 52: turn to “no”
PasswordAuthentication no root@tel4vn:~# systemctl restart ssh
Putty:
Nhập IP của server cần remote:
Thêm privatekey vào Options controlling SSH authentication:
Sau đó ấn Open để kết nối.
Mobaxterm:
Ấn tổ hộp phím Ctrl + Shift + N để tạo session mới, sau đó chọn tab SSH
Điền thông tin IP, port của server cần kết nối và chọn đường dẫn lưu privatekey sau đó ấn OK để lưu lại và kết nối.
Chúc các bạn thành công!
Powered by BetterDocs
Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *
Δ
Ghi nhớ tôi
Chưa đăng ký? Đăng ký
Năm sinh
Bạn đã đăng ký? Đăng nhập ngay