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

비밀번호

댓글 작성자
 




... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12780정성태8/13/202118190.NET Framework: 1088. C# - 버스 노선 및 위치 정보 조회 API 사용을 위한 기초 라이브러리 [2]
12779정성태8/13/202120650개발 환경 구성: 596. 공공 데이터 포털에서 버스 노선 및 위치 정보 조회 API 사용법
12778정성태8/12/202116092오류 유형: 755. PyCharm - "Manage Repositories"의 목록이 나오지 않는 문제
12777정성태8/12/202118480오류 유형: 754. Visual Studio - Input or output cannot be redirected because the specified file is invalid.
12776정성태8/12/202116387오류 유형: 753. gunicorn과 uwsgi 함께 사용 시 ERR_CONNECTION_REFUSED
12775정성태8/12/202130679스크립트: 22. 파이썬 - 윈도우 환경에서 개발한 Django 앱을 WSL 환경의 gunicorn을 이용해 실행
12774정성태8/11/202120665.NET Framework: 1087. C# - Collection 개체의 다중 스레드 접근 시 "Operations that change non-concurrent collections must have exclusive access" 예외 발생
12773정성태8/11/202119804개발 환경 구성: 595. PyCharm - WSL과 연동해 Django App을 윈도우에서 리눅스 대상으로 개발
12772정성태8/11/202119828스크립트: 21. 파이썬 - 윈도우 환경에서 개발한 Django 앱을 WSL 환경의 uwsgi를 이용해 실행 [1]
12771정성태8/11/202118631Windows: 196. "Microsoft Windows Subsystem for Linux Background Host" / "Vmmem"을 종료하는 방법
12770정성태8/11/202118142.NET Framework: 1086. C# - Windows Forms 응용 프로그램의 자식 컨트롤 부하파일 다운로드1
12769정성태8/11/202114980오류 유형: 752. Python - ImportError: No module named pip._internal.cli.main 두 번째 이야기
12768정성태8/10/202116334.NET Framework: 1085. .NET 6에 포함된 신규 BCL API [1]파일 다운로드1
12767정성태8/10/202117280오류 유형: 752. Python - ImportError: No module named pip._internal.cli.main
12766정성태8/9/202115371Java: 32. closing inbound before receiving peer's close_notify
12765정성태8/9/202117279Java: 31. Cannot load JDBC driver class 'org.mysql.jdbc.Driver'
12764정성태8/9/202155287Java: 30. XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid
12763정성태8/9/202119653Java: 29. java.lang.NullPointerException - com.mysql.jdbc.ConnectionImpl.getServerCharset
12762정성태8/8/202121926Java: 28. IntelliJ - Unable to open debugger port 오류
12761정성태8/8/202118248Java: 27. IntelliJ - java: package javax.inject does not exist [2]
12760정성태8/8/202114350개발 환경 구성: 594. 전용 "Command Prompt for ..." 단축 아이콘 만들기
12759정성태8/8/202120536Java: 26. IntelliJ + Spring Framework + 새로운 Controller 추가 [2]파일 다운로드1
12758정성태8/7/202120282오류 유형: 751. Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
12757정성태8/7/202120895Java: 25. IntelliJ + Spring Framework 프로젝트 생성
12756정성태8/6/202117555.NET Framework: 1084. C# - .NET Core Web API 단위 테스트 방법 [1]파일 다운로드1
12755정성태8/5/202118993개발 환경 구성: 593. MSTest - 단위 테스트에 static/instance 유형의 private 멤버 접근 방법파일 다운로드1
... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...