Super Kawaii Cute Cat Kaoani
본문 바로가기

Linux

[Linux] 가상머신 커스터마이징 (공개키 ssh 접속)

728x90

🧷 Key-pair 생성

먼저, Key-pair를 생성한다.

ssh-keygen -q -N "" -f myvm.pem

 

🧷 이미지 복사

cp CentOS7-Base.qcow2 myvm.qcow2

 

🧷 이미지 커스터마이징 ⭐️

virt-customize -a myvm.qcow2 --install httpd,git,vim --firstboot-command 'systemctl enable httpd' --mkdir /root/.ssh --run-command 'chmod 700 /root/.ssh' --upload myvm.pem.pub:/root/.ssh/authorized_keys --run-command 'chmod 644 /root/.ssh/authorized_keys' --selinux-relabel

 

  • 이미지 파일 이름 설정 : -a
-a myvm.qcow2

 

  • 설치 : --install
--install httpd,vim

 

  • 처음 부팅 시 실행할 명령어 : --firstboot-command
--firstboot-command 'systemctl enable httpd'

 

  • 디렉터리 생성 : --mkdir
--mkdir /root/.ssh

 

  • 부팅 시 자동으로 실행할 명령어 : --upload
--upload myvm.pem.pub:/root/.ssh/authorized_keys

 

  • 파일 업로드 : --run-command
--run-command 'chmod 644 /root/.ssh/authorized_keys'

 

  • SELinux 다시 설정 : --selinux-relabel
--selinux-relabel

 

🧷 가상머신 설치

virt-install --name myvm --vcpus 1 --ram 1024 --disk /shared/myvm.qcow2 --graphics vnc -v --import --noautoconsole
  • 이미 생성된 디스크 이미지 사용하여 가상머신 생성 : --import

🧷 가상머신 ip 확인

virsh domifaddr myvm

🧷 원격접속

 

  • 위에서 확인한 ip 주소로 ssh 접속
ssh -i myvm.pem [IP 주소]
728x90