Microsoft MVP성태의 닷넷 이야기
Windows: 282. 윈도우 운영체제에 추가된 ssh 서버(Win32-OpenSSH) [링크 복사], [링크+제목 복사],
조회: 603
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

윈도우 운영체제에 추가된 ssh 서버(Win32-OpenSSH)

과거에, psexec를 이용한 초보적인 수준의 ssh 흉내를 내는 것이 가능했는데요,

윈도우에서도 유닉스처럼 명령행으로 원격 접속하는 방법
; https://www.sysnet.pe.kr/2/0/1245

어느새 윈도우도 ConPTY를 결합한 ConHost를 구현하면서 *NIX처럼 ssh를 통한 터미널 연결 지원이 추가됐습니다.

Get started with OpenSSH for Windows
; https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse

그렇습니다, 우리가 리눅스를 통해 알고 있던 그 sshd가,

openssh-portable
; https://github.com/PowerShell/openssh-portable

윈도우 버전으로 거의 자연스럽게 포팅이 돼 서비스가 되는 것입니다. 현재, ConPTY는 Windows 10 / Windows Server 2019 이상에서만 제공하는데요, 직접 실습해 볼까요? ^^

예를 들어, Windows Server 2022 환경에 OpenSSH Server를, "Settings", "Apps" / "Apps & features"의 "Optional features" 링크로 들어가 "Add a feature"를 클릭해 "OpenSSH Server"를 설치할 수 있습니다.

win32_open_ssh_1.png

서버 측에 "OpenSSH Server" 구성 요소를 설치했으면, 편의상 "Services" 관리 콘솔에서 "OpenSSH SSH Server" 서비스의 "Startup Type"을 "Automatic"으로 설정하고 서비스를 시작합니다. (Windows Sevrer 2025의 경우 해당 구성 요소는 기본적으로 설치돼 있으므로 서비스 관리자에서 "OpenSSH SSH Server" 항목만 시작해 주면 됩니다.)




클라이언트는 Windows 11로 해 볼 텐데요, 기본적으로 이미 ssh 클라이언트가 포함돼 있기 때문에 별도 설치는 필요 없습니다. 단지 "Settings"에서 "System" / "Optional features"로 들어가 설치 여부를 확인하고, 만약 없다면 "Add an optional features"의 "View features"를 클릭해 설치할 수 있습니다.

윈도우로의 ssh 접속 방법은 리눅스 경험을 그대로 살릴 수 있습니다.

형식)
c:\temp> ssh [domain]\[username]@[servername]
* [domain]의 경우 로컬 계정이라면 생략 가능

예) Active Directory 이름: testad, 사용자 ID: testusr, 서버 IP: 192.168.100.50인 경우
c:\temp> ssh testad\testusr@192.168.100.50

예) 로컬 사용자 ID: testusr, 서버 IP: 192.168.100.50인 경우
c:\temp> ssh testusr@192.168.100.50

C:\temp> where ssh
C:\Windows\System32\OpenSSH\ssh.exe

C:\temp> ssh
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
           [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
           [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
           [-i identity_file] [-J [user@]host[:port]] [-L address]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-Q query_option] [-R address] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] destination [command]

C:\temp> ssh "testad\testusr@192.168.100.50"
The authenticity of host '192.168.100.50 (192.168.100.50)' can't be established.
ED25519 key fingerprint is SHA256:Sn...[생략]...78.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.100.50' (ED25519) to the list of known hosts.
testad\testusr@192.168.100.50's password:
Microsoft Windows [Version 10.0.17763.5830]
(c) 2018 Microsoft Corporation. All rights reserved.

testad\testusr@TESTPC C:\Users\testusr>

연결이 되면, Prompt의 문자열("testad\testusr@TESTPC")을 통해 그것이 서버 환경임을 인지할 수 있습니다.




당연히, linux 측에서도 ssh를 통해 윈도우에 접속하는 것이 가능합니다. 방법은 동일한데요,

// Active Directory 도메인: testad
// 계정: testusr
// 서버: TESTPC

$ ssh "testad\testusr@TESTPC"
testad\testusr@TESTPC's password: 

접속 후, 터미널 화면은 clear되고 윈도우 프롬프트임을 알리는 화면, 즉, 윈도우에서 cmd.exe를 띄웠을 때 보이는 그 메시지가 화면에 나옵니다.

Microsoft Windows [Version 10.0.20348.2527]
(c) Microsoft Corporation. All rights reserved.

testad\testusr@TESTPC C:\Users\testusr>

멋지죠? ^^ (참고로, 윈도우 방화벽이 활성화된 경우 "OpenSSH-Server-In-TCP" 항목을 허용해 주면 됩니다.)




그나저나, 한 가지 궁금해지는군요. ^^ 리눅스의 경우 shell 환경에서 관리자 권한의 명령어를 수행하기 위해 sudo 명령어를 사용하는데요, 그렇다면 윈도우 ssh 환경에서는 어떻게 해야 할까요? 윈도우는 "User Access Control" 제어 하에 있기 때문에 관리자 권한을 획득하려면 반드시 윈도우 창이 떠야 하고, 프로세스도 새롭게 떠야 합니다. 문제는 ssh 자체에는 그런 기능이 없다는 건데요, 윈도우는 이것을 어떻게 해결했을까요?

이걸 해결이라고 봐야 할지 모르겠는데, "관리자 그룹"에 속한 사용자로 ssh 접속을 하면 (UAC가 활성화된 윈도우의 제약에서 벗어나) 이미 관리자 권한을 획득한 상태로 접속이 됩니다. 예를 들어, 대상 컴퓨터에 Remote Desktop으로 접속해 띄운 일반 cmd 창에서는 c:\WINDOWS\System32\drivers\etc 디렉터리에 파일 생성을 할 수 없지만,

// 윈도우 운영 체제에서 실행한 cmd 창

c:\WINDOWS\System32\drivers\etc> echo %USERNAME%
testusr

c:\WINDOWS\System32\drivers\etc> copy con file.txt
test
Access is denied.
        0 file(s) copied.

ssh로 접속한 경우에는 별도의 추가 동작 없이 파일을 생성할 수 있습니다.

// ssh로 접속한 경우 (접속 계정이 관리자 그룹에 속한 경우 ssh 창의 타이틀 바에 있는 텍스트가 접속 순간에 "Administrator"라고 표시)

testusr@TESTPC c:\WINDOWS\System32\drivers\etc> echo %USERNAME%
testusr

testusr@TESTPC c:\WINDOWS\System32\drivers\etc> copy con test.txt
test
^Z
        1 file(s) copied.

개인적으로 내심 sudo 명령어의 추가된 사연이,

Windows 11 24H2 - sudo 추가
; https://www.sysnet.pe.kr/2/0/13818

이런 ssh 환경을 지원하기 위한 것이라고 생각했는데, ^^ 그건 아니었던 것 같습니다. 참고로, 관리자 권한에 속한 사용자로 ssh 접속을 한 경우 아래와 같은 프로세스 구조를 가집니다.

sshd.exe (Mandatory Label - System)
   ㄴ sshd.exe (Mandatory Label - System)
        ㄴ sshd.exe (Mandatory Label - High)
              ㄴ conhost.exe (Mandatory Label - High)
                   ㄴ cmd.exe (Mandatory Label - High)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 8/6/2025]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  82  83  84  85  86  87  [88]  89  90  ...
NoWriterDateCnt.TitleFile(s)
11804정성태1/24/201922404Windows: 155. diskpart - remove letter 이후 재부팅 시 다시 드라이브 문자가 할당되는 경우
11803정성태1/10/201921273디버깅 기술: 121. windbg - 닷넷 Finalizer 스레드가 멈춰있는 현상
11802정성태1/7/201922724.NET Framework: 805. 두 개의 윈도우를 각각 실행하는 방법(Windows Forms, WPF)파일 다운로드1
11801정성태1/1/201923608개발 환경 구성: 427. Netsh의 네트워크 모니터링 기능 [3]
11800정성태12/28/201823077오류 유형: 509. WCF 호출 오류 메시지 - System.ServiceModel.CommunicationException: Internal Server Error
11799정성태12/19/201825573.NET Framework: 804. WPF(또는 WinForm)에서 UWP UI 구성 요소 사용하는 방법 [3]파일 다운로드1
11798정성태12/19/201823717개발 환경 구성: 426. vcpkg - "Building vcpkg.exe failed. Please ensure you have installed Visual Studio with the Desktop C++ workload and the Windows SDK for Desktop C++"
11797정성태12/19/201819056개발 환경 구성: 425. vcpkg - CMake Error: Problem with archive_write_header(): Can't create '' 빌드 오류
11796정성태12/19/201820744개발 환경 구성: 424. vcpkg - "File does not have expected hash" 오류를 무시하는 방법
11795정성태12/19/201824319Windows: 154. PowerShell - Zone 별로 DNS 레코드 유형 정보 조회 [1]
11794정성태12/16/201820102오류 유형: 508. Get-AzureWebsite : Request to a downlevel service failed.
11793정성태12/16/201822996개발 환경 구성: 423. NuGet 패키지 제작 - Native와 Managed DLL을 분리하는 방법 [1]
11792정성태12/11/201821034Graphics: 34. .NET으로 구현하는 OpenGL (11) - Per-Pixel Lighting파일 다운로드1
11791정성태12/11/201821317VS.NET IDE: 130. C/C++ 프로젝트의 시작 프로그램으로 .NET Core EXE를 지정하는 경우 닷넷 디버깅이 안 되는 문제 [1]
11790정성태12/11/201820762오류 유형: 507. Could not save daemon configuration to C:\ProgramData\Docker\config\daemon.json: Access to the path 'C:\ProgramData\Docker\config' is denied.
11789정성태12/10/201835455Windows: 153. C# - USB 장치의 연결 및 해제 알림을 위한 WM_DEVICECHANGE 메시지 처리 [2]파일 다운로드2
11788정성태12/4/201820957오류 유형: 506. SqlClient - Value was either too large or too small for an Int32.Couldn't store <2151292191> in ... Column
11787정성태11/29/201824797Graphics: 33. .NET으로 구현하는 OpenGL (9), (10) - OBJ File Format, Loading 3D Models파일 다운로드1
11786정성태11/29/201821892오류 유형: 505. OpenGL.NET 예제 실행 시 "Managed Debugging Assistant 'CallbackOnCollectedDelegate'" 예외 발생
11785정성태11/21/201823089디버깅 기술: 120. windbg 분석 사례 - ODP.NET 사용 시 Finalizer에서 System.AccessViolationException 예외 발생으로 인한 비정상 종료
11784정성태11/18/201822019Graphics: 32. .NET으로 구현하는 OpenGL (7), (8) - Matrices and Uniform Variables, Model, View & Projection Matrices파일 다운로드1
11783정성태11/18/201821405오류 유형: 504. 윈도우 환경에서 docker가 설치된 컴퓨터 간의 ping IP 주소 풀이 오류
11782정성태11/18/201819508Windows: 152. 윈도우 10에서 사라진 "Adapters and Bindings" 네트워크 우선순위 조정 기능 - 두 번째 이야기
11781정성태11/17/201824168개발 환경 구성: 422. SFML.NET 라이브러리 설정 방법 [1]파일 다운로드1
11780정성태11/17/201824483오류 유형: 503. vcpkg install bzip2 빌드 에러 - "Error: Building package bzip2:x86-windows failed with: BUILD_FAILED"
11779정성태11/17/201825054개발 환경 구성: 421. vcpkg 업데이트 [1]
... 76  77  78  79  80  81  82  83  84  85  86  87  [88]  89  90  ...