03 bước để login SSH trên remote server không cần password

Bạn có nhiều server linux cần quản lý, mỗi lần ssh tới mỗi server thì lại hỏi password rất phiền phức, tốn nhiều thời gian?
Bạn cần login vào các server đó theo giao thức ssh mà không cần hỏi password?
Tôi sẽ giúp bạn ^^!
Chúng ta sẽ sử dụng ssky-keygen và ssh-copy-id để làm điều này.
  • ssh-keygen sẽ tạo ra public và private keys.
  • ssh-copy-id sẽ copy public key của máy local đến remote-host’s authorized_keys.
  • ssh-copy-id đồng thời sẽ gán quyền cho máy local trên remote-host’s home, thư mục ~/.ssh, và ~/.ssh/authorized_keys.

Các bước thực hiện như sau

Bước 1: Tạo ra public và private keys sử dụng ssh-key-gen trên localhost.
lecuong@HQ.ITDept$
lecuong@HQ.ITDept$ ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/lecuong/.ssh/id_rsa.
Your public key has been saved in /home/lecuong/.ssh/id_rsa.pub.
The key fingerprint is:
d5:de:96:2f:f2:35:93:b3:f2:af:90:95:78:31:31:f9 lecuong@HQ.ITDept
Bước 2: Copy public key lên remote-host sử dụng ssh-copy-id
lecuong@HQ.ITDept$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host-ip
lecuong@remote-host’s password:
Now try logging into the machine, with “ssh ‘remote-host’”, and check in:
.ssh/authorized_keys
to make sure we haven’t added extra keys that you weren’t expecting.
Note: ssh-copy-id appends the keys to the remote-host’s .ssh/authorized_key.
Bước 3: Đăng nhập trên remote-host không cần password
lecuong@HQ.ITDept$ ssh remote-host-ip
Last login: Thur Sept 26 11:45:59 2013 from 10.165.123.123
Đơn giản thế thôi ^^!



Để bắt đầu tham gia Giao dịch tài chính:


Comments are closed.