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

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  69  70  71  [72]  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
12201정성태3/18/202021355오류 유형: 611. git-credential-manager.exe: Using credentials for username "Personal Access Token". [1]
12200정성태3/18/202021359VS.NET IDE: 145. NuGet + Github 라이브러리 디버깅 관련 옵션 3가지 - "Enable Just My Code" / "Enable Source Link support" / "Suppress JIT optimization on module load (Managed only)"
12199정성태3/17/202019299오류 유형: 610. C# - CodeDomProvider 사용 시 Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '...\f2_6uod0.tmp'.
12198정성태3/17/202022822오류 유형: 609. SQL 서버 접속 시 "Cannot open user default database. Login failed."
12197정성태3/17/202022314VS.NET IDE: 144. .NET Core 콘솔 응용 프로그램을 배포(publish) 시 docker image 자동 생성 - 두 번째 이야기 [1]
12196정성태3/17/202018595오류 유형: 608. The ServicedComponent being invoked is not correctly configured (Use regsvcs to re-register).
12195정성태3/16/202021291.NET Framework: 902. C# - 프로세스의 모든 핸들을 열람 - 세 번째 이야기
12194정성태3/16/202024323오류 유형: 607. PostgreSQL - Npgsql.NpgsqlException: sorry, too many clients already
12193정성태3/16/202021364개발 환경 구성: 485. docker - SAP Adaptive Server Enterprise 컨테이너 실행 [1]
12192정성태3/14/202022262개발 환경 구성: 484. docker - Sybase Anywhere 16 컨테이너 실행
12191정성태3/14/202023770개발 환경 구성: 483. docker - OracleXE 컨테이너 실행 [1]
12190정성태3/14/202018622오류 유형: 606. Docker Desktop 업그레이드 시 "The process cannot access the file 'C:\Program Files\Docker\Docker\resources\dockerd.exe' because it is being used by another process."
12189정성태3/13/202023928개발 환경 구성: 482. Facebook OAuth 처리 시 상태 정보 전달 방법과 "유효한 OAuth 리디렉션 URI" 설정 규칙
12188정성태3/13/202030105Windows: 169. 부팅 시점에 실행되는 chkdsk 결과를 확인하는 방법
12187정성태3/12/202018945오류 유형: 605. NtpClient was unable to set a manual peer to use as a time source because of duplicate error on '...'.
12186정성태3/12/202020171오류 유형: 604. The SysVol Permissions for one or more GPOs on this domain controller and not in sync with the permissions for the GPOs on the Baseline domain controller.
12185정성태3/11/202021057오류 유형: 603. The browser service was unable to retrieve a list of servers from the browser master...
12184정성태3/11/202023317오류 유형: 602. Automatic certificate enrollment for local system failed (0x800706ba) The RPC server is unavailable. [3]
12183정성태3/11/202019878오류 유형: 601. Warning: DsGetDcName returned information for \\[...], when we were trying to reach [...].
12182정성태3/11/202021744.NET Framework: 901. C# Windows Forms - Vista/7 이후의 Progress Bar 업데이트가 느린 문제파일 다운로드1
12181정성태3/11/202022103기타: 76. 재현 가능한 최소한의 예제 프로젝트란? - 두 번째 예제파일 다운로드1
12180정성태3/10/202019218오류 유형: 600. "Docker Desktop for Windows" - EXPOSE 포트가 LISTENING 되지 않는 문제
12179정성태3/10/202029893개발 환경 구성: 481. docker - PostgreSQL 컨테이너 실행
12178정성태3/10/202023433개발 환경 구성: 480. Linux 운영체제의 docker를 위한 tcp 바인딩 추가 [1]
12177정성태3/9/202022612개발 환경 구성: 479. docker - MySQL 컨테이너 실행
12176정성태3/9/202021936개발 환경 구성: 478. 파일의 (sha256 등의) 해시 값(checksum) 확인하는 방법
... 61  62  63  64  65  66  67  68  69  70  71  [72]  73  74  75  ...