免密scp解決ssh_exchange_identification:read connection reset by peer 原因

王一洋發表於2019-01-10

在區塊鏈docker映象轉移過程中,需要經常在伺服器之間拷貝資源,scp需要密碼很不方便,因此需要免密操作。以下是方法以及錯誤解決辦法。

1. 在伺服器 S 上執行如下命令來生成配對金鑰: 
ssh-keygen -t rsa 
按照提示操作,注意,不要輸入passphrase,因為我的之前已經操作過,所以還提示了是否覆蓋,輸入 "y"回車就可以。其他提示資訊如下 
Generating public/private rsa key pair. 
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa. 
Your public key has been saved in /root/.ssh/id_rsa.pub. 
The key fingerprint is: 
ff:8e:85:68:85:94:7c:2c:46:b1:e5:2d:41:5c:e8:9b root@localhost.domain

2. 將 /root/.ssh/ 目錄中的 id_rsa.pub 檔案複製到 伺服器 B 的 /root/.ssh/ 目錄中,並改名為 authorized_keys。 
scp .ssh/id_rsa.pub root@192.168.0.2:/root/.ssh/authorized_keys

以後從伺服器 S scp 到伺服器 B 就不需要密碼了。

3、伺服器改了密碼,試過密碼多次後出現:

ssh_exchange_identification: read: Connection reset by peer

可以通過ssh -v檢視連線時詳情

OpenSSH_6.6.1, OpenSSL 1.0.1k-fips 8 Jan 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to xxx [xx] port 22.
debug1: Connection established.
debug1: identity file /home/yanue/.ssh/id_rsa type -1
debug1: identity file /home/yanue/.ssh/id_rsa-cert type -1
debug1: identity file /home/yanue/.ssh/id_dsa type -1
debug1: identity file /home/yanue/.ssh/id_dsa-cert type -1
debug1: identity file /home/yanue/.ssh/id_ecdsa type -1
debug1: identity file /home/yanue/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/yanue/.ssh/id_ed25519 type -1
debug1: identity file /home/yanue/.ssh/id_ed25519-cert type -1

最後找打解決方法:

vi /etc/hosts.allow

追加:

sshd: ALL

重啟ssh就ok了

service sshd restart

 

相關文章