2017-10-30 5 views
2

"ec2-user"로서 SSH 및 SCP를 EC2 인스턴스에 잘 적용 할 수 있습니다.ec2-ssh에 사용자를 추가해도 scp는 작동하지 않습니다

다른 사용자와 마찬가지로 SSH를 사용할 수도 있지만 SCP는 할 수 없습니다.

"ec2-user"가 아닌 다른 사용자로 SCP를 시도하면 ec2 인스턴스가 새 (dup) ssh-agent를 생성하고 파일을받지 못합니다.

-

우리는 SSH 에이전트를 사용하여 각 사용자가 자신의 .PEM 키를 ssh를 추가합니다. 공개 키는 각 사용자의 ~/.ssh/authorized_keys에있는 원격 ec2 인스턴스에 추가됩니다. 다시 말하지만, 우리의 설정은 SSH를 위해 잘 작동합니다.

Host my-ec2.com 
    User jdoe 
    Hostname 123.123.123.123 
    ForwardAgent yes 
    IdentityFile /Users/jonathan/.ssh/key.pem 

그리고 EC2에는 원격 ~/스푸핑/설정, 우리는 단지 시스템 기본값 사용이 없습니다 : (로컬) /home/jonathan/.ssh/config의

내용입니다.

로컬 및/또는 원격 ssh-agent의 작동 방식이 SCP와는 다른 이유는 SSH와 다릅니다.

도움이 될 것입니다!

디버그 정보이 작동

- "EC2 사용자"로 SSH는 :

$> ssh-add /Users/jonathan/.ssh/key.pem 
$> ssh [email protected] 

이 너무 작품 - SSH를 "가 jdoe"로 :

$> ssh-add /Users/jonathan/.ssh/key.pem 
$> ssh [email protected] 

이를 ec2 사용자로도 작동합니다.

$> ssh-add /Users/jonathan/.ssh/key.pem 
$> scp foo.txt [email protected]:~/. 
foo.txt  100% 197 2.5KB/s 00:00 

이 작동하지 않습니다 - "가 jdoe"로 SCP를 :

$> ssh-add /Users/jonathan/.ssh/key.pem 
$> scp foo.txt [email protected]:~/. 
Agent PID 12345 

는 또한 모든 실패 SCP 시도가 EC2 여기

$> ssh-add /Users/jonathan/.ssh/key.pem 
$> ssh [email protected] 
$> ps -x | grep ssh-agent 
11677 ?  Ss  0:00 ssh-agent 
11708 ?  Ss  0:00 ssh-agent 
11742 ?  Ss  0:00 ssh-agent 
11919 ?  Ss  0:00 ssh-agent 
12345 ?  Ss  0:00 ssh-agent 
### a duplicate copy if ssh-agent is running with PID 12345 
### there are as many ssh-agent running as failed SCP attempts... 

에서 중복 SSH 에이전트를 생성하면 전체 "SCP의 사본입니다 -v "출력 :

$> scp -v foo.txt [email protected]:~/. 
Executing: program /usr/bin/ssh host my-ec2.com, user jdoe, command scp -v -t ~/foo 
OpenSSH_7.4p1, LibreSSL 2.5.0 
debug1: Reading configuration data /Users/jonathan/.ssh/config 
debug1: /Users/jonathan/.ssh/config line 2: Applying options for * 
debug1: /Users/jonathan/.ssh/config line 7: Applying options for my-ec2.com 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: Connecting to 123.123.123.123 [123.123.123.123] port 22. 
debug1: Connection established. 
debug1: key_load_public: No such file or directory 
debug1: identity file /Users/jonathan/.ssh/cps-keypair.pem type -1 
debug1: key_load_public: No such file or directory 
debug1: identity file /Users/jonathan/.ssh/cps-keypair.pem-cert type -1 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_7.4 
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000 
debug1: Authenticating to 123.123.123.123:22 as 'jdoe' 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: algorithm: curve25519-sha256 
debug1: kex: host key algorithm: ecdsa-sha2-nistp256 
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none 
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none 
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY 
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:j4kSCIWNUz5k7LHHK+n9iR9kxktihrD4X/srX4uX/5U 
debug1: Host '123.123.123.123' is known and matches the ECDSA host key. 
debug1: Found key in /Users/jonathan/.ssh/known_hosts:1 
debug1: rekey after 134217728 blocks 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: rekey after 134217728 blocks 
debug1: SSH2_MSG_EXT_INFO received 
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512> 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey 
debug1: Next authentication method: publickey 
debug1: Offering RSA public key: /Users/jonathan/.ssh/cps-keypair.pem 
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279 
debug1: Authentication succeeded (publickey). 
Authenticated to 123.123.123.123 ([123.123.123.123]:22). 
debug1: channel 0: new [client-session] 
debug1: Requesting [email protected] 
debug1: Entering interactive session. 
debug1: pledge: network 
debug1: client_input_global_request: rtype [email protected] want_reply 0 
debug1: Sending command: scp -v -t ~/foo 
Agent pid 24732 
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 
debug1: channel 0: free: client-session, nchannels 1 
debug1: fd 0 clearing O_NONBLOCK 
debug1: fd 1 clearing O_NONBLOCK 
Transferred: sent 2812, received 2696 bytes, in 0.2 seconds 
Bytes per second: sent 15501.9, received 14862.4 
debug1: Exit status 0 

답변

1

대화 형 세션의 경우에만 EC2 인스턴스에서 ssh-agent을 시작하십시오. scp에 필요하지 않으며 출력으로 인해 scp이 실패합니다.

분명히 ssh-agent은 EC2 인스턴스 (예 : Bash 프로필)에서 로그인하는 동안 호출됩니다.

시작을 방지하려면 EC2 인스턴스에서 프로필 스크립트를 조정하십시오. 예 : (EC2 인스턴스에서 Bash를 사용한다고 가정 할 때) if 문을 추가하면됩니다.

if [[ "$-" == *i* ]]; then 
    # <start ssh agent here> 
fi 
+0

고맙습니다! 그것이 바로 그 것이었다. ~/.bash_profile (첫 번째 문제) 대신 ~/.bashrc에서 시작된 ssh-agent가 있었고 비 대화식 세션도 시작되었습니다 (두 번째 문제). 당신의 대답은 확실했습니다. –

관련 문제