偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

如何在CentOS/RHEL上設(shè)置SSH免密碼登錄

系統(tǒng) Linux 系統(tǒng)運維
作為系統(tǒng)管理員,你計劃在Linux上使用OpenSSH,完成日常工作的自動化。本文為你提供SSH免密碼登錄CentOS/RHEL的基本認知和快速指南。

       作為系統(tǒng)管理員,你計劃在 Linux 上使用 OpenSSH,完成日常工作的自動化,比如文件傳輸、備份數(shù)據(jù)庫轉(zhuǎn)儲文件到另一臺服務(wù)器等。為實現(xiàn)該目標(biāo),你需要從主機 A 能自動登錄到主機 B。自動登錄也就是說,要在 shell 腳本中使用ssh,而無需要輸入任何密碼。

  本文會告訴你怎樣在 CentOS/RHEL 上設(shè)置 SSH 免密碼登錄。自動登錄配置好以后,你可以通過它使用 SSH (Secure Shell)和安全復(fù)制 (SCP)來移動文件。

  SSH 是開源的,是用于遠程登錄的最為可靠的網(wǎng)絡(luò)協(xié)議。系統(tǒng)管理員用它來執(zhí)行命令,以及通過 SCP 協(xié)議在網(wǎng)絡(luò)上向另一臺電腦傳輸文件。

  通過配置 SSH 免密碼登錄,你可以享受到如下的便利:

◆用腳本實現(xiàn)日常工作的自動化。 

◆增強 Linux 服務(wù)器的安全性。這是防范虛擬專用服務(wù)器(VPS)遭受暴力破解攻擊的一個推薦的方法,SSH 密鑰單憑暴力破解是幾乎不可攻破的。

  什么是 ssh-keygen

  ssh-keygen 是一個用來生成、創(chuàng)建和管理 SSH 認證用的公私鑰的工具。通過 ssh-keygen 命令,用戶可以創(chuàng)建支持SSH1 和 SSH2 兩個協(xié)議的密鑰。ssh-keygen 為 SSH1 協(xié)議創(chuàng)建 RSA 密鑰,SSH2 則可以是 RSA 或 DSA。

  什么是 ssh-copy-id

  ssh-copy-id 是用來將本地公鑰拷貝到遠程的 authorized_keys 文件的腳本命令,它還會將身份標(biāo)識文件追加到遠程機器的 ~/.ssh/authorized_keys 文件中,并給遠程主機的用戶主目錄適當(dāng)?shù)牡臋?quán)限。

  SSH 密鑰

  SSH 密鑰為登錄 Linux 服務(wù)器提供了更好且安全的機制。運行 ssh-keygen 后,將會生成公私密鑰對。你可以將公鑰放置到任意服務(wù)器,從持有私鑰的客戶端連接到服務(wù)器的時,會用它來解鎖。兩者匹配時,系統(tǒng)無需密碼就能解除鎖定。

  在 CentOS 和 RHEL 上設(shè)置免密碼登錄 SSH

  以下步驟在 CentOS 5/6/7、RHEL 5/6/7 和 Oracle Linux 6/7 上測試通過。

  節(jié)點1:192.168.0.9 節(jié)點2 : 192.168.l.10

  步驟一 :

  測試節(jié)點1到節(jié)點2的連接和訪問:

  1. [root@node1 ~]# ssh root@192.168.0.10 
  2. The authenticity of host '192.168.0.10 (192.168.0.10)' can't be established. 
  3. RSA key fingerprint is 6d:8f:63:9b:3b:63:e1:72:b3:06:a4:e4:f4:37:21:42. 
  4. Are you sure you want to continue connecting (yes/no)? yes 
  5. Warning: Permanently added '192.168.0.10' (RSA) to the list of known hosts. 
  6. root@192.168.0.10's password
  7. Last login: Thu Dec 10 22:04:55 2015 from 192.168.0.1 
  8. [root@node2 ~]# 

  步驟二:

  使用 ssh-key-gen 命令生成公鑰和私鑰,這里要注意的是可以對私鑰進行加密保護以增強安全性。

  1. [root@node1 ~]# ssh-keygen 
  2. Generating public/private rsa key pair. 
  3. Enter file in which to save the key (/root/.ssh/id_rsa): 
  4. Enter passphrase (empty for no passphrase): 
  5. Enter same passphrase again: 
  6. Your identification has been saved in /root/.ssh/id_rsa. 
  7. Your public key has been saved in /root/.ssh/id_rsa.pub. 
  8. The key fingerprint is
  9. b4:51:7e:1e:52:61:cd:fb:b2:98:4b:ad:a1:8b:31:6d root@node1.ehowstuff.local 
  10. The key's randomart image is
  11. +--[ RSA 2048]----+ 
  12. |          . ++   | 
  13. |         o o  o  | 
  14. |        o o o  . | 
  15. |       . o + ..  | 
  16. |        S   .  . | 
  17. |         .   .. .| 
  18. |        o E oo.o | 
  19. |         = ooo.  | 
  20. |        . o.o.   | 
  21. +-----------------+ 

  步驟三:

  用 ssh-copy-id 命令將公鑰復(fù)制或上傳到遠程主機,并將身份標(biāo)識文件追加到節(jié)點2的 ~/.ssh/authorized_keys 中:

  1. [root@node1 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.0.10 
  2. root@192.168.0.10's password
  3. Now try logging into the machine, with "ssh '192.168.0.10'"and check in
  4.  
  5. .ssh/authorized_keys 
  6.  
  7. to make sure we haven't added extra keys that you weren't expecting. 

  步驟四:

  驗證免密碼 SSH 登錄節(jié)點2:

  1. [root@node1 ~]# ssh root@192.168.0.10 
  2.   Last login: Sun Dec 13 14:03:20 2015 from www.ehowstuff.local 

  我希望這篇文章能幫助到你,為你提供 SSH 免密碼登錄 CentOS / RHEL 的基本認知和快速指南。

 

責(zé)任編輯:武曉燕 來源: Linux中國
相關(guān)推薦

2023-09-13 22:54:06

2015-10-21 11:03:21

ssh登錄Linux

2020-03-02 14:06:54

CentOS 8FFmpegLinux

2021-03-07 22:36:02

LinuxSSH電子郵件

2015-12-21 13:19:23

CentosRHEL 6.XWetty

2019-12-02 11:50:09

CentOS 8VirtualBoxLinux

2017-04-24 18:10:27

DrupalCentOSFedora

2017-04-11 13:20:06

CentOSRHELFedora

2012-09-28 10:12:55

2015-04-09 09:08:20

2019-10-12 10:24:06

CentOSRHELCockpit

2023-03-16 08:55:51

RHEL 8MiniKube開源

2019-11-14 09:20:15

CentOS 8RHEL 8Nagios Core

2014-07-24 10:17:25

CentOSSquid

2019-06-05 10:20:09

安全更新命令Linux

2018-03-09 09:45:52

LinuxSSH登錄導(dǎo)語

2022-11-17 09:52:12

RHEL 9Node.js

2021-07-07 07:09:51

Centos8 RescueSSH

2024-01-30 20:06:18

RHELVLAN

2019-10-14 15:00:12

Centos 8 RHEL 8VNC
點贊
收藏

51CTO技術(shù)棧公眾號