Microsoft MVP성태의 닷넷 이야기
Windows: 282. 윈도우 운영체제에 추가된 ssh 서버(Win32-OpenSSH) [링크 복사], [링크+제목 복사],
조회: 635
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  112  113  114  115  [116]  117  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
11092정성태11/3/201634986.NET Framework: 618. C# - NAudio를 이용한 MP3 파일 재생 [5]파일 다운로드1
11091정성태11/3/201628090VC++: 104. std::call_once를 이용해 thread-safe한 Singleton 객체 생성파일 다운로드1
11090정성태11/1/201629562VC++: 103. C++ CreateTimerQueue, CreateTimerQueueTimer 예제 코드 [9]파일 다운로드1
11089정성태11/1/201629914디버깅 기술: 82. Windows 10을 위한 Symbol(PDB) 파일 내려받는 방법 [2]
11088정성태11/1/201632471.NET Framework: 617. C# - AForge.NET을 이용한 MP4 동영상 파일 재생 [7]파일 다운로드1
11087정성태11/1/201626663.NET Framework: 616. AForge.Video.FFMPEG를 최신 버전의 ffmpeg 파일로 의존성을 변경하는 방법파일 다운로드1
11086정성태11/1/201621374오류 유형: 366. The Microsoft Passport Container service terminated with the following error: General access denied error
11085정성태10/27/201636625.NET Framework: 615. C# - AForge.NET을 이용한 웹캠 영상 출력 [2]파일 다운로드1
11084정성태10/26/201624015오류 유형: 365. The User Profile Service service failed to the sign-in.
11083정성태10/26/201630474Windows: 131. 윈도우 10에서 사라진 "Adapters and Bindings" 네트워크 우선 순위 조정 기능 [1]
11082정성태10/26/201633371.NET Framework: 614. C# - DateTime.Ticks의 정밀도 [4]파일 다운로드1
11081정성태10/26/201622827오류 유형: 364. You need to fix your Microsoft Account for apps on your other devices to be able to launch apps and continue experiences on this device.
11080정성태10/24/201626853Windows: 130. Windows Server 2016 Nano 서버 설치 방법
11079정성태10/21/201624005Windows: 129. Windows Server 2016 설치 CD에 있는 Convert-WindowsImage.ps1 사용 방법 정리
11078정성태10/21/201625093Windows: 128. Windows Server 2016 Nano 서버 VHD 이미지 만드는 방법 - TP5 기준
11077정성태10/21/201623040오류 유형: 363. Active Directory 서버의 NETLOGON 서비스가 멈췄을 때 발생하는 문제
11076정성태10/21/201622882오류 유형: 362. 윈도우 백업 시 오류 - 0x80780040
11075정성태10/20/201622680Windows: 127. Convert-WindowsImage.ps1 사용 방법 정리
11074정성태10/20/201632552Windows: 126. Windows Server 2016 평가판을 정식 버전으로 라이선스 변경하는 방법
11073정성태10/20/201628803.NET Framework: 613. 윈도우 데스크톱 응용 프로그램(예: Console)에서 알림 메시지(Toast notifications) 띄우기 [1]파일 다운로드1
11072정성태10/20/201625777VC++: 102. 새로 추가한 ATL COM 객체가 regsvr32.exe로 등록이 안 되는 문제
11071정성태10/20/201628430.NET Framework: 612. UWP(유니버설 윈도우 플랫폼) 앱에서 콜백 함수 내에서의 UI 요소 접근 방법 [1]
11070정성태10/20/201621482Windows: 125. 윈도우 서버 2016 마이그레이션
11069정성태10/19/201629876.NET Framework: 611. C++ 개발자들을 위한 C# Thread 동작 방식 [2]
11068정성태10/19/201632941Windows: 124. 윈도우 운영체제의 시간 함수 (5) - TSC(Time Stamp Counter)와 QueryPerformanceCounter [12]파일 다운로드1
11067정성태10/18/201628484Windows: 123. 윈도우 운영체제의 시간 함수 (4) - RTC, TSC, PM Clock, HPET Timer [2]
... 106  107  108  109  110  111  112  113  114  115  [116]  117  118  119  120  ...