Window 상에서 Cygwin을 통해 SSH 설정하기

0. Cygwin 설치하기

"하둡 프로그래밍: 기초에서 실무까지 하둡의 모든것" 책을 보던 중 Windows에 Hadoop 을 셋업하는 법을 실행해 보았다. 먼저 sshd 를 사용하는데 이를 CYGWIN기반에서 인스톨하고 기동해야 한다. 책 대로 해보다가 sshd 가 cygwin에서 기동되지 않아 여러 시행 착오를 거쳤다.


1. Cygwin에서 SSH  설정하기.

셋업시 발견한 가장 중요한 요소들을 아래와 같다. 

가. cygwin 터미널을 관리자 권한으로 실행한다. 관리자 권한으로 실행하지 않을 경우 권한 문제로 ssh 환경 파일들의 Write가 되지 않는 문제가 발생할 수 있다.

나.  Enter the value of CYGWIN for the daemon: [] 에 ntsec을 입력한다. ntsec은 windows의 보안정책을 따르겠다는 것임. ( 아마도 ntsecurity의 줄임말인듯 )

다. cyg_server의 password 설정 시 반드시 엄격한 패스워드 규칙사용 필요.
( set the password between 5 to 8 characters and combination of Uppercase, lowercase and numbers. 예를 들어 Jdk1234# )  설정 시 cyg_server라는 권한을 가진 account 가 사용되는데 해당 account의 password를 cyg_server, 1111 같이 기억하기 편한 password를 입력하였더니 아래와 같은 오류가 발생하였다.

*** Warning: Creating the user 'cyg_server' failed!  Reason:
▒▒ȣ▒▒ ▒▒ȣ ▒▒å ▒䱸 ▒▒▒׿▒ ▒▒▒▒ ▒ʽ▒▒ϴ▒. ▒ּ▒ ▒▒ȣ ▒▒▒▒, ▒▒ȣ ▒▒▒⵵ ▒▒ ▒▒ȣ ▒▒▒ ▒䱸 ▒▒▒▒▒▒ Ȯ▒▒▒Ͻʽÿ▒.

NET HELPMSG 2245▒▒(▒▒) ▒Է▒▒ϸ▒ ▒▒▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒ֽ▒▒ϴ▒.

cygwin에서 한글이 깨지는 바람에 오류 메시지가 무슨 내용인지 몰랐는데, 이유를 찾고 보니 , 패스워드가 너무 쉽게 생성이 되었다는 것이다.  Cygwin에서의 한글 설정도 먼저 필요해 보인다.




2. Windows 환경 변수 설정.

내 컴퓨터->오른쪽버튼 클릭->속성->고급 시스템 설정->환경변수 에서 새로운 환경 변수를 생성 CYGWIN=ntsec 입력

시스템 변수인 PATH에도 Cygwin의 bin 디렉토리를 추가. 

PATH=......;C:\Dev\cygwin64\bin


3. 관리자 권한으로 cygwin 실행.

Cygwin 아이콘을 오른쪽 마우스 클릭하고 관리자 권한으로 실행.



4. 기존 설정된 sshd 환경 Reset

처음 설정하는 단계에서는 필요없으나 본인은 여러번 셋업하면서 실패하였기 때문에 기존에 만들어진 sshd 관련 파일 및 프로세스 down

가.  cygrunsrv -R sshd 로 sshd 서비스 삭제.
나.  /etc 디렉토리 밑에 ssh_로 시작하는 파일들및 , sshd_config 삭제
rm ssh_*; rm sshd_config


5. 이제 ssh-host-config로 ssh 셋업 명령어 수행.  no 또는 yes로 설정.

strict mode 설정 : no , privilege seperation은 yes로 설정

sshd를 서비스로 install : yes , Enter the value of CYGWIN for the daemon: [] ntsec

cyg_server이름을 바꿀 필요 없음. no로 설정

주의 : password는 반드시 엄격한 패스워드 규칙사용 필요.
set the password between 5 to 8 characters and combination of Uppercase, lowercase and numbers. 예를 들어 Jdk1234#


$ ssh-host-config

*** Info: Generating missing SSH host keys
ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
*** Info: Creating default /etc/ssh_config file
*** Info: Creating default /etc/sshd_config file

*** Info: StrictModes is set to 'yes' by default.
*** Info: This is the recommended setting, but it requires that the POSIX
*** Info: permissions of the user's home directory, the user's .ssh
*** Info: directory, and the user's ssh key files are tight so that
*** Info: only the user has write permissions.
*** Info: On the other hand, StrictModes don't work well with default
*** Info: Windows permissions of a home directory mounted with the
*** Info: 'noacl' option, and they don't work at all if the home
*** Info: directory is on a FAT or FAT32 partition.
*** Query: Should StrictModes be used? (yes/no) no
    -- StrictMode 는 no로 설정한다.
*** Info: Privilege separation is set to 'sandbox' by default since
*** Info: OpenSSH 6.1.  This is unsupported by Cygwin and has to be set
*** Info: to 'yes' or 'no'.
*** Info: However, using privilege separation requires a non-privileged account
*** Info: called 'sshd'.
*** Info: For more info on privilege separation read /usr/share/doc/openssh/README.privsep.
*** Query: Should privilege separation be used? (yes/no) yes

  -- privilege seperation은 yes로 설정

*** Info: Updating /etc/sshd_config file

*** Query: Do you want to install sshd as a service?
*** Query: (Say "no" if it is already installed as a service) (yes/no) yes

-- sshd를 서비스로 install : yes

*** Query: Enter the value of CYGWIN for the daemon: [] ntsec

--ntsec으로 설정

*** Info: On Windows Server 2003, Windows Vista, and above, the
*** Info: SYSTEM account cannot setuid to other users -- a capability
*** Info: sshd requires.  You need to have or to create a privileged
*** Info: account.  This script will help you do so.

*** Info: It's not possible to use the LocalSystem account for services
*** Info: that can change the user id without an explicit password
*** Info: (such as passwordless logins [e.g. public key authentication]
*** Info: via sshd) when having to create the user token from scratch.
*** Info: For more information on this requirement, see
*** Info: https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-nopasswd1

*** Info: If you want to enable that functionality, it's required to create
*** Info: a new account with special privileges (unless such an account
*** Info: already exists). This account is then used to run these special
*** Info: servers.

*** Info: Note that creating a new user requires that the current account
*** Info: have Administrator privileges itself.

*** Info: The following privileged accounts were found: 'cyg_server' .

*** Info: This script plans to use 'cyg_server'.
*** Info: 'cyg_server' will only be used by registered services.

*** Query: Do you want to use a different name? (yes/no) no

-- cyg_server이름을 바꿀 필요 없음. no로 설정

*** Query: Please enter the password for user 'cyg_server':
*** Query: Reenter:
*** Query: Please enter the password for user 'cyg_server':
*** Query: Reenter:
-- 주의 : password는 반드시 엄격한 패스워드 규칙사용 필요. 예를 들어 jdk1234#

*** Info: The sshd service has been installed under the 'cyg_server'
*** Info: account.  To start the service now, call `net start sshd' or
*** Info: `cygrunsrv -S sshd'.  Otherwise, it will start automatically
*** Info: after the next reboot.

*** Info: Host configuration finished. Have fun!


6. sshd 서비스 기동

net start sshd 또는 cygrunsrv -S sshd


이렇게 기동하면 윈도우즈 서비스에 기동이 표시된다.


만일 제대로 기동이 되지 않을 시에 아래와 같은 메시지를 출력하면 이 또한 password 설정 문제 이다.


cygrunsrv: Error starting a service: StartService:  Win32 error 1069:


해당 메시지는 window log on 을 pass하지 못했으며, password 가 기준에 맞게 설정되지 않았다는 것이다. ( 대문자, 소문자, 숫자를 섞어서 5 ~8 문자가 되어야 한다. )


이경우 아래와 같이 cygwin shell 에서 cyg_server의 패스워드를 변경 후에 윈도우 control 서비스에서 CYGWIN sshd 를 오른쪽 마우스로 선택한 뒤에 Log On 탭에서 변경된 패스워드를 입력해 준다.


$ passwd sshd_server

(set the password between 5 to 8 characters and combination of Uppercase, lowercase and numbers.)

다음에 변경된 패스워드를 윈도우의 서비스 에서 로그온 탭에서 동일하게 변경한다.





아래 블로그에서 많은 도움을 받았다. 특히 cygwin에 대한 한글 설정도 잘 나와 있는 좋은 자료 이다.

http://yard.tistory.com/entry/CygWin-SSHD



+ Recent posts