![Ansible이 Windows에서 사용자를 생성하면 사용자 이름에 ".EC2AMAZ-ELNOCH3"이 추가됩니다.](https://rvso.com/image/760989/Ansible%EC%9D%B4%20Windows%EC%97%90%EC%84%9C%20%EC%82%AC%EC%9A%A9%EC%9E%90%EB%A5%BC%20%EC%83%9D%EC%84%B1%ED%95%98%EB%A9%B4%20%EC%82%AC%EC%9A%A9%EC%9E%90%20%EC%9D%B4%EB%A6%84%EC%97%90%20%22.EC2AMAZ-ELNOCH3%22%EC%9D%B4%20%EC%B6%94%EA%B0%80%EB%90%A9%EB%8B%88%EB%8B%A4..png)
Packer와 Ansible을 프로비저너로 사용하여 Windows Server 2019 AMI를 생성했습니다.
사용자를 추가 jenkins
하고 SSH 파일(공개/개인 키, Known_hosts, Authorized_keys)을 에 복사했습니다 C:\Users\jenkins\.ssh
.
이것은 내 Ansible 플레이북의 관련 부분입니다.
- name: Ensure user jenkins is present
ansible.windows.win_user:
name: jenkins
password: ***REDACTED***
state: present
groups:
- Users
- name: Create directory structure
ansible.windows.win_file:
path: C:\Temp\
state: directory
- name: Allow write and execute access to User jenkins
ansible.windows.win_acl:
user: jenkins
path: C:\Temp
type: allow
rights: ExecuteFile,Write
- name: Copy SSH keys
ansible.windows.win_copy:
src: ./files/.ssh
dest: C:\Users\jenkins
vars:
ansible_become_user: jenkins
ansible_become_password: ***REDACTED***
# The tmp dir must be set when using win_copy as another user
# This ensures the become user will have permissions for the operation
# Make sure to specify a folder both the ansible_user and the become_user have access to (i.e not %TEMP% which is user specific and requires Admin)
ansible_remote_tmp: C:\Temp
이 AMI에서 EC2 인스턴스를 시작합니다.
SSH로 로그인합니다.
ssh -i ~/.ssh/***REDACTED***.pem jenkins@ec2-***REDACTED***.compute.amazonaws.com -vvv
SSH 키로 로그인하지 않았지만 비밀번호로 로그인할 수 있습니다.
SSH 디버그 로그는 다음과 같습니다.
debug3: load_hostkeys: loaded 1 keys from ***REDACTED***
debug1: Host 'ec2-***REDACTED***.compute.amazonaws.com' is known and matches the ECDSA host key.
debug1: Found key in /home/amedee/.ssh/known_hosts:161
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/amedee/.ssh/***REDACTED***.pem explicit
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: start over, passed a different list publickey,password,keyboard-interactive
debug3: preferred gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/amedee/.ssh/***REDACTED***.pem
debug3: sign_and_send_pubkey: RSA SHA256:3OWWXRDheAUWZ9kxRiSJPvwFy1/Nh3//CdbLirDuFSM
debug3: sign_and_send_pubkey: signing using rsa-sha2-512 SHA256:3OWWXRDheAUWZ9kxRiSJPvwFy1/Nh3//CdbLirDuFSM
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug2: we did not send a packet, disable method
debug3: authmethod_lookup keyboard-interactive
debug3: remaining preferred: password
debug3: authmethod_is_enabled keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug3: send packet: type 50
debug2: we sent a keyboard-interactive packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: userauth_kbdint: disable: no info_req_seen
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred:
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
jenkins@***REDACTED***.compute.amazonaws.com's password:
그러면 Windows에서는 다음과 같은 환영 인사를 받습니다.
Microsoft Windows [Version 10.0.17763.1637]
(c) 2018 Microsoft Corporation. All rights reserved.
jenkins@EC2AMAZ-ELNOCH3 C:\Users\jenkins.EC2AMAZ-ELNOCH3>
jenkins
그래서 나는 user 로 로그인하지 않고 user 로 로그인했습니다 jenkins.EC2AMAZ-ELNOCH3
.
사용자 jenkins
도 존재합니다:
jenkins@EC2AMAZ-ELNOCH3 C:\Users\jenkins.EC2AMAZ-ELNOCH3>dir ..
Volume in drive C has no label.
Volume Serial Number is E43B-9F7E
Directory of C:\Users
12/11/2020 02:19 PM <DIR> .
12/11/2020 02:19 PM <DIR> ..
12/11/2020 01:51 PM <DIR> Administrator
12/11/2020 02:02 PM <DIR> jenkins
12/11/2020 02:22 PM <DIR> jenkins.EC2AMAZ-ELNOCH3
12/12/2018 07:45 AM <DIR> Public
0 File(s) 0 bytes
6 Dir(s) 12,552,163,328 bytes free
Ansible을 사용하여 복사한 SSH 파일이 있습니다.
jenkins@EC2AMAZ-ELNOCH3 C:\Users\jenkins.EC2AMAZ-ELNOCH3>dir ..\jenkins\.ssh
Volume in drive C has no label.
Volume Serial Number is E43B-9F7E
Directory of C:\Users\jenkins\.ssh
12/11/2020 02:02 PM <DIR> .
12/11/2020 02:02 PM <DIR> ..
11/13/2020 10:57 AM 1,221 authorized_keys
11/13/2020 10:57 AM 1,675 id_rsa
11/13/2020 10:57 AM 401 id_rsa.pub
11/13/2020 10:57 AM 7,962 known_hosts
4 File(s) 11,259 bytes
2 Dir(s) 12,552,081,408 bytes free
사용자 이름에 이것을 추가하여 SSH 연결을 시도하면 .EC2AMAZ-ELNOCH3
비밀번호로 로그인할 수 없습니다.
ssh -i ~/.ssh/***REDACTED***.pem jenkins.EC2AMAZ-ELNOCH3@ec2-***REDACTED***.compute.amazonaws.com -vvv
.
.
.
debug1: Next authentication method: password
jenkins.EC2AMAZ-ELNOCH3@ec2-***REDACTED***.compute.amazonaws.com's password:
debug3: send packet: type 50
debug2: we sent a password packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
Permission denied, please try again.
jenkins.EC2AMAZ-ELNOCH3@ec2-***REDACTED***.compute.amazonaws.com's password:
사용자로 로그인하면 에서 jenkins.EC2AMAZ-ELNOCH3
파일을 복사 하고 연결을 끊습니다. 다음에 SSH로 로그인하면 비밀번호 없는 로그인이 작동합니다. 이는 SSH 키가 정확하지만 잘못된 디렉토리에 있음을 증명합니다.C:\Users\jenkins\.ssh\
C:\Users\jenkins.EC2AMAZ-ELNOCH3\.ssh\
이 사용자가 존재하는 것을 원하지 않습니다 jenkins.EC2AMAZ-ELNOCH3
. 사용자만 존재하는지 어떻게 확인할 수 있나요 jenkins
?
참고로 저는 Linux에만 익숙하므로 귀하의 답변에 고급 Windows 용어가 포함되어 있으면 자세히 설명해주세요. 제가 마지막으로 사용한 Windows 버전은 Windows 3.11이었습니다. Ansible을 사용하여 어떤 작업을 하는 것도 이번이 처음이지만, 그 요점을 이해하고 있다는 확신이 듭니다.
답변1
jenkins@EC2AMAZ-ELNOCH3
jenkins
에 사용자로 로그인되어 있음을 의미합니다.기계 EC2AMAZ-ELNOCH3
.
C:\Users\jenkins.EC2AMAZ-ELNOCH3
Windows에서 로그인 시 해당 폴더가 C:\Users\jenkins
이미 존재하지만 사용자에게는 올바른 폴더가 아니라는 사실을 발견했음을 의미합니다 jenkins
. 따라서 Windows에서는 새 사용자 프로필 폴더를 만들어야 했습니다.
bar
라는 로컬 사용자 계정으로 호출된 컴퓨터에 로그인하는 경우 foo
기본 사용자 프로필 폴더는 다음과 같습니다 C:\Users\foo
. 그러나 이 폴더가 이미 존재하고 Windows가 어떤 이유로든 이 폴더를 실제 사용자 계정에 매핑할 수 없는 경우 새 폴더가 생성됩니다. 중복된 폴더 이름을 해결하기 위해 Windows는 여기에 컴퓨터 이름을 추가하므로 새 사용자 프로필 폴더가 호출됩니다 C:\users\foo.bar
.
이는 사용자 이름과는 아무런 관련이 없으며 여전히 foo
.
왜 이런 일이 일어났는지에 대해서는 전혀 알 수 없습니다. 그러나 이는 사용자 프로필 폴더가 중복되는 표준 Windows 동작입니다.
답변2
사용커뮤니티.windows.win_user_profile– Windows 사용자 프로필을 관리합니다. 사용자가 생성된 직후에 홈 디렉터리를 생성한 다음 파일을 복사하세요.
Ansible에서 이를 수행하는 방법은 다음과 같습니다.
- name: Ensure user jenkins is present
ansible.windows.win_user:
name: jenkins
password: ***REDACTED***
state: present
groups:
- Users
- name: Create a profile for user jenkins at C:\Users\jenkins
community.windows.win_user_profile:
username: jenkins
name: jenkins
state: present
- name: Create directory structure
ansible.windows.win_file:
path: C:\Temp\
state: directory
- name: Allow write and execute access to User jenkins
ansible.windows.win_acl:
user: jenkins
path: C:\Temp
type: allow
rights: ExecuteFile,Write
- name: Copy SSH keys
ansible.windows.win_copy:
src: ./files/.ssh
dest: C:\Users\jenkins
vars:
ansible_become_user: jenkins
ansible_become_password: ***REDACTED***
# The tmp dir must be set when using win_copy as another user
# This ensures the become user will have permissions for the operation
# Make sure to specify a folder both the ansible_user and the become_user have access to (i.e not %TEMP% which is user specific and requires Admin)
ansible_remote_tmp: C:\Temp