Linux 설치시 설치상태나, 설치 단계에서부터 몇가지 체크하고 모니터링 할게 있어서, SSH로 접근 하면 좀 편하지 않을까 싶어서, Ananconda가 Load되면서 SSH를 뛰울 수 있는 방법이 없나~ 하다가... 아주 썩 깔끔한 방법은 아니지만, 우선 급한대로 원하는 결과만(?) 만들어 내어 일단 메모해둔다. (보안같은 부분은 추가적으로 해줘야 한다.. SSH가 root로 비번도 없이 로그인 되니... pass를 미리 설정하던지, Allow인자를 활용하던지.. 아무튼, 꼭 보안은 별도로 신경 써줘야 한다...)


1. 환경

TFTP/PXE로 isolinux 이미지들을 바탕으로 설치

isolinux중에서 initrd.img 이미지를 편집하는 것으로 처리.


2. initrd.img 풀어 해치기~

# cd <initrd.img가 있는 디렉토리>

# mkdir initrd

# cd initrd

# zcat ../initrd.img | cpio -idv

# ls -al

drwxr-xr-x 15 root root 4096 Apr  8 19:54 .

drwxr-xr-x  4 root root 4096 Apr  8 19:53 ..

-rw-r--r--  1 root root  134 Apr  8 19:54 .bash_history

lrwxrwxrwx  1 root root    4 Apr  8 19:54 bin -> sbin

-rw-r--r--  1 root root   78 Apr  8 19:54 .buildstamp

drwxr-xr-x  2 root root 4096 Apr  8 19:54 dev

drwxr-xr-x 16 root root 4096 Apr  8 19:54 etc

drwxr-xr-x 18 root root 4096 Apr  8 19:54 firmware

lrwxrwxrwx  1 root root   10 Apr  8 19:54 init -> /sbin/init

drwxr-xr-x  3 root root 4096 Apr  8 19:54 lib

drwxr-xr-x  4 root root 4096 Apr  8 19:54 lib64

drwxr-xr-x  3 root root 4096 Apr  8 19:54 modules

drwxr-xr-x  2 root root 4096 Apr  8 19:54 proc

-rw-r--r--  1 root root  157 Apr  8 19:54 .profile

drwxr-xr-x  2 root root 4096 Apr  8 19:54 sbin

drwxr-xr-x  2 root root 4096 Apr  8 19:54 selinux

drwxr-xr-x  2 root root 4096 Apr  8 19:54 sys

drwxr-xr-x  2 root root 4096 Apr  8 19:54 tmp

drwxr-xr-x  7 root root 4096 Apr  8 19:54 usr

drwxr-xr-x  7 root root 4096 Apr  8 19:54 var


3. ssh 데몬 실행을 위한 준비
(다행이 Anaconda 이미지에 sshd 바이너리나 기본적인 설정파일은 미리 준비되어 있었다.)

# cd <이전 단계에서 initrd.img를 풀어둔 디렉토리>

# ssh-keygen -b 1024 -f etc/ssh/ssh_host_key -N "" -t rsa1

# ssh-keygen -d -f etc/ssh/ssh_host_rsa_key -N "" -t rsa

# ssh-keygen -d -f etc/ssh/ssh_host_dsa_key -N "" -t dsa

# cp -a etc/ssh/sshd_config.anaconda etc/ssh/sshd_config

# cat etc/ssh/sshd_config
(Port를 변경하고 싶으면 변경하면 되고, 기타 옵션 조정을 원하면 알아서....)

Port 22

HostKey /etc/ssh/ssh_host_key

HostKey /etc/ssh/ssh_host_rsa_key

HostKey /etc/ssh/ssh_host_dsa_key

PermitRootLogin yes

IgnoreRhosts yes

StrictModes yes

X11Forwarding yes

X11DisplayOffset 10

PrintMotd yes

XAuthLocation /sbin/xauth

KeepAlive yes

SyslogFacility AUTHPRIV

RSAAuthentication yes

PasswordAuthentication yes

PermitEmptyPasswords yes

PermitUserEnvironment yes


4. Anaconda 로딩 시, sshd 자동 실행 처리
(이부분이 참... 원래 init 스크립트가 그냥 bash 쉘 스크립트였는데, CentOS6부터 바꼈는지, 컴파일 되어 있다..ㅡ.ㅡ;; 어쨌든, 훼이크성 편법이지만, 부팅중 실행되는 바이너리 중 하나를 바꿔치기 해서 /usr/sbin/sshd가 실행되도록 임시 처리 했다.... 만만한게 auditd 였다.. 추후 정상적인 init프로세스에 추가 할수 있는 방법을 찾으면 수정..)

# cd <이전 단계에서 initrd.img를 풀어둔 디렉토리>

# cd sbin

# mv auditd auditd.orig

# cat > auditd << EOF

#!/bin/bash

/sbin/sshd

/sbin/auditd.orig

EOF

# chmod 755 auditd


5. SSH 설정작업은 끝... 작업했던 디렉토리 내용을 다시 initrd.img로 묶어준다.

# cd <이전 단계에서 initrd.img를 풀어둔 디렉토리>

# find . | cpio -H newc -o | gzip -9 > ../initrd.img


6. 이제 다시 설치를 시도해서, 설치 과정중 해당 서버로 SSH접속을 시도해본다.

- Password는 없이 바로 로그인 된다.

- 다른 사전 작업이 필요하다면, 각자 처리 해둔다.


이상, 끝..... 서두에 이야기 했듯이... sshd를 실행하는 것이 정상적이진 않다... 시간이 되는대로 CentOS 6 Anaconda의 init과정을 좀 파봐야 겠다... 뭔가 나오면 그때 문서 업데이트하기로 하고 오늘은 이정도로만....

Posted by 사랑줍는거지
,