윈도우 계열에서 OpenSSH가 설치가 잘 안되는 경우가 있다.( 내가 겪은 상황 )
"설정 > 앱 > 선택적 기능"으로 이동하면 OpenSSH 클라이언트 설치가 존재하지만,
무슨 이유인지 설치가 안된다.
로그 분석하고 싶지만, 귀차니즘으로 인해 OpenSSH를 다운로드 받아 간단하게 설치를 해보자.
OpenSSH 다운로드
C:\OpenSSH 등 원하는 경로에 폴더 생성하여 압축 해제
sshd_config_default 파일 편집
... Port 22 PasswordAuthentication yes ... #Match Group administrators # AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys |
Match Group administrators 주석을 안하면 SSH 비밀번호 없이 로그인하고자 하면 실패나는 경우가 있어 미리 처리
Powershell을 관리자 모드로 실행
스크립트 실행 허용 여부 확인( Restricted 일경우 install때 오류남 )
PS C:\OpenSSH> ExecutionPolicy
PS C:\OpenSSH> Restricted
아래 명령어로 스크립트 실행 허용
PS C:\OpenSSH> Set-ExecutionPolicy Unrestricted
PS C:\OpenSSH> ExecutionPolicy
PS C:\OpenSSH> Unrestricted
명령어 실행 순서
- 환경 변수 등록( 압축 푼 경로 )
- sshd 설치
- Windows Service 등록
- 방화벽 등록( Windows Server 2008 R2에선 오류남 - 방화벽 인바운드 규칙에 사용할 포트 등록으로 수동 처리 )
Port 지정
PS C:\OpenSSH> setx PATH "$env:path;C:\OpenSSH" -m
PS C:\OpenSSH> install-sshd.ps1
PS C:\OpenSSH> Set-Service sshd -StartupType Automatic; Set-Service ssh-agent -StartupType Automatic; Start-Service sshd; Start-Service ssh-agent
PS C:\OpenSSH> New-NetFirewallRule -DisplayName "OpenSSH-Server-In-TCP" -Direction Inbound -LocalPort 22 -Protocol TCP -Action Allow
SSH, SCP 등 명령어를 선호하는 도구에서 마음껏 사용하기 끗!
PS C:\OpenSSH> SSH id@127.0.0.1