2016-03-13 98 views
-2

我有兩臺運行Linux a @ A和b @ B的計算機,麥克風連接到B. 使用A,我登錄到b @ B以啓動python腳本有可能實時收聽麥克風。ssh主機密鑰驗證失敗,如果使用子進程運行

這裏是我的代碼:

#!/usr/bin/env python 
# -*-coding:Latin-1 -* 

import threading 
import time 
import pygame 
import sys 
import subprocess 
import os 
import signal 

global listenProcess 
global listenProcess2 

listenProcess = subprocess.Popen('arecord -D plughw:1,0 -f dat'.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
listenProcess2 = subprocess.Popen('ssh -C [email protected] aplay -f dat'.split(), stdin=listenProcess.stdout, stderr=subprocess.PIPE) 

如果我啓動命令:

arecord -D plughw:1,0 -f dat | ssh -C [email protected] aplay -f dat 

它運行完美,我可以聽到由麥克風記錄。但如果是從我的Python腳本,它提出了以下錯誤:

Host key verification failed

我試圖「清潔」 known_hosts文件時產生錯誤的建議。 我也試過paramiko,但似乎不是我的解決方案。

我已經跑出了想法。

感謝

編輯: 運行arecord -D plughw:1,0 -f dat | ssh -v -C [email protected] aplay -f dat 顯示:

[email protected] ~/Documents $ arecord -D plughw:1,0 -f dat | ssh -v -C [email protected] aplay -f dat 
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo 
OpenSSH_6.7p1 Raspbian-5+deb8u1, OpenSSL 1.0.1k 8 Jan 2015 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: /etc/ssh/ssh_config line 19: Applying options for * 
debug1: Connecting to 192.168.1.33 [192.168.1.33] port 22. 
debug1: Connection established. 
debug1: identity file /home/pi/.ssh/id_rsa type 1 
debug1: key_load_public: No such file or directory 
debug1: identity file /home/pi/.ssh/id_rsa-cert type -1 
debug1: key_load_public: No such file or directory 
debug1: identity file /home/pi/.ssh/id_dsa type -1 
debug1: key_load_public: No such file or directory 
debug1: identity file /home/pi/.ssh/id_dsa-cert type -1 
debug1: key_load_public: No such file or directory 
debug1: identity file /home/pi/.ssh/id_ecdsa type -1 
debug1: key_load_public: No such file or directory 
debug1: identity file /home/pi/.ssh/id_ecdsa-cert type -1 
debug1: key_load_public: No such file or directory 
debug1: identity file /home/pi/.ssh/id_ed25519 type -1 
debug1: key_load_public: No such file or directory 
debug1: identity file /home/pi/.ssh/id_ed25519-cert type -1 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Raspbian-5+deb8u1 
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.9p1 Ubuntu-2ubuntu0.1 
debug1: match: OpenSSH_6.9p1 Ubuntu-2ubuntu0.1 pat OpenSSH* compat 0x04000000 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client aes128-ctr [email protected] [email protected] 
debug1: kex: client->server aes128-ctr [email protected] [email protected] 
debug1: sending SSH2_MSG_KEX_ECDH_INIT 
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY 
debug1: Server host key: ECDSA e1:fc:46:c9:5f:66:f8:d5:8f:13:27:cb:2d:a5:7b:17 
debug1: Host '192.168.1.33' is known and matches the ECDSA host key. 
debug1: Found key in /home/pi/.ssh/known_hosts:1 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey,password 
debug1: Next authentication method: publickey 
debug1: Offering RSA public key: /home/pi/.ssh/id_rsa 
debug1: Server accepts key: pkalg ssh-rsa blen 279 
debug1: Enabling compression at level 6. 
debug1: Authentication succeeded (publickey). 
Authenticated to 192.168.1.33 ([192.168.1.33]:22). 
debug1: channel 0: new [client-session] 
debug1: Requesting [email protected] 
debug1: Entering interactive session. 
debug1: client_input_global_request: rtype [email protected] want_reply 0 
debug1: Sending environment. 
debug1: Sending env LC_PAPER = fr_FR.UTF-8 
debug1: Sending env LC_ADDRESS = fr_FR.UTF-8 
debug1: Sending env LC_MONETARY = fr_FR.UTF-8 
debug1: Sending env LC_NUMERIC = fr_FR.UTF-8 
debug1: Sending env LC_TELEPHONE = fr_FR.UTF-8 
debug1: Sending env LC_IDENTIFICATION = fr_FR.UTF-8 
debug1: Sending env LANG = en_GB.UTF-8 
debug1: Sending env LC_MEASUREMENT = fr_FR.UTF-8 
debug1: Sending env LC_TIME = fr_FR.UTF-8 
debug1: Sending env LC_NAME = fr_FR.UTF-8 
debug1: Sending command: aplay -f dat 
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo 

因爲它在命令行啓動,這是工作。

編輯: 好吧,我想我可能已經找到原因:由於我的整個python腳本啓動了一個全屏顯示pygame在我的遠程pc上,我需要啓動腳本與sudo。因此,我認爲當它啓動子進程ssh時,它也試圖在計算機A上作爲sudo進行連接。我認爲這是我的代碼的簡單版本正在工作,但如果我將其作爲sudo啓動它,它會要求我密碼。問題是,我仍然需要啓動腳本作爲sudo。

+0

'split'引入錯誤分裂的風險 - 也許這是原因。要麼自己構建序列,要麼使用'shell = True'(有適當的考慮)。 –

+0

yes,listenProcess2 = subprocess.Popen('ssh -C a @ A aplay -f dat',shell ='True',stdin = listenProcess.stdout,stderr = subprocess.PIPE)引發同樣的錯誤 – bsignoret

+0

您在那裏引用了True。我認爲它需要是布爾型的,而不是字符串 –

回答

0

警告: 的解決方案可能不適合每一個人,因爲它不是完全安全的,但對於在我的2臺電腦直接連接沒有互聯網連接我的具體問題,風險不高。

解決方案: 在服務器上,我這樣做:

sudo su - root # log in as root 
ssh-keygen -t rsa # generate a rsa key 
cat .ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys' # add the key to the other computer 
service ssh restart # restart ssh just in case 

這樣,它的工作。謝謝你的幫助。

相關問題