
사용자 정의 ec2 ami 이미지를 생성하고 USERVM
아래 단계에 따라 사용자에 대한 ec2 키 쌍 인증을 사용하여 aws 인스턴스를 인증하려고 합니다.
- 아미 창작 .
- EC2-실행-인스턴스...
- ec2-create-keypair를 사용하여 프라이빗 키를 생성합니다.
- ~/.ssh/keypair.pem에 개인 키를 저장하고 권한을 제공했습니다.
- 다음을 사용하여 AWS 인스턴스를 연결합니다.
ssh -v -i ~/.ssh/keypair.pem [email protected]
해당 디버그 로그:
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to ec2-52-23-236-90.compute-1.amazonaws.com [52.23.236.90] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/keypair_14_10_721pm.pem type -1
debug1: identity file /root/.ssh/keypair_14_10_721pm.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-4+deb7u2
debug1: match: OpenSSH_6.0p1 Debian-4+deb7u2 pat OpenSSH* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 12:6d:09:82:fd:4b:0d:1d:88:3d:2a:65:31:c0:ad:cd
The authenticity of host 'ec2-52-23-236-90.compute-1.amazonaws.com (52.23.236.90)' can't be established.
ECDSA key fingerprint is 12:6d:09:82:fd:4b:0d:1d:88:3d:2a:65:31:c0:ad:cd.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-52-23-236-90.compute-1.amazonaws.com,52.23.236.90' (ECDSA) to the list of known hosts.
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
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: Trying private key: /root/.ssh/keypair_14_10_721pm.pem
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
[email protected]'s password:
debug1: Authentication succeeded (password).
Authenticated to ec2-52-23-236-90.compute-1.amazonaws.com
sshd_config는 다음과 같습니다.
# Package generated configuration file
# See the sshd(8) manpage for details
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
#PermitRootLogin yes
PermitRootLogin without-password
StrictModes no
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
#IgnoreUserKnownHosts yes
PermitEmptyPasswords no
ChallengeResponseAuthentication no
#PasswordAuthentication yes
# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
UseDNS no
내가 겪고 있는 문제는 사용자로 로그인을 시도할 때 AWS 인스턴스에서 비밀번호를 묻는 문제입니다 USERVM
. 사용자의 공개 키는 USERVM
부팅 시 생성되어 aws 인스턴스 아래에 배치됩니다 /home/USERVM/.ssh/authorized_keys
. 그러나 이름이 지정된 사용자에 대한 동일한 접근 방식은 root
암호를 묻지 않고도 잘 작동합니다. 여기에 도움을 주시면 감사하겠습니다.
편집: 사용자에 대한 권한은 USERVM
다음과 같습니다.
$ sudo ls -la /home/
total 36
drwxr-xr-x 6 root root 4096 Oct 14 12:34 .
drwxr-xr-x 27 root root 4096 Oct 15 16:39 ..
drwxr-xr-x 2 admin www-data 4096 Oct 14 12:34 admin
drwxr-xr-x 3 USERVM www-data 4096 Oct 15 16:42 USERVM
drwx------ 2 root root 16384 Oct 14 12:38 lost+found
drwxrwsrwx 22 tuser www-data 4096 Oct 15 16:40 tuser
$ sudo ls -la /home/USERVM/
total 16
drwxr-xr-x 3 USERVM www-data 4096 Oct 15 16:42 .
drwxr-xr-x 6 root root 4096 Oct 14 12:34 ..
-rw------- 1 USERVM www-data 105 Oct 15 16:42 .bash_history
drwx------ 2 root root 4096 Oct 15 16:38 .ssh
$ sudo ls -la /home/USERVM/.ssh/
total 12
drwx------ 2 root root 4096 Oct 15 16:38 .
drwxr-xr-x 3 USERVM www-data 4096 Oct 15 16:42 ..
-rw------- 1 root root 1203 Oct 15 16:39 authorized_keys
사용자에게 동일한 절차로 로그인을 시도하면 비밀번호를 묻지만 admin
비밀번호 를 묻지 않고 작동합니다.USERVM
root
답변1
나는 이것이 승인된 키 파일에 대한 일반적인 권한 문제일 것으로 예상했지만 미묘하게 다릅니다.소유권또한 정확해야 합니다. 즉, 인증을 위해 파일을 사용하는 사용자가 파일을 소유해야 합니다.
파일과 디렉터리는 그룹 쓰기가 가능하지 않아야 하기 때문에 그룹 소유권은 그다지 중요하지 않다고 생각하지만, 이를 사용자의 기본 그룹으로 설정하는 것이 가장 좋습니다.
어쨌든 chown -R USERVM:www-data ~USERVM/.ssh
문제는 해결되었습니다.