SFTP는 "Secure File Transfer Protocol"의 약자로, 원격으로 파일을 안전하게 전송하기 위한 프로토콜
현재 작업은 윈도우에 wsl에 openssh 서버를 설치하는 방법
대부분 비슷할거임
Windows Subsystem for Linux(WSL)를 활용해 Ubuntu 등 리눅스 환경에 SFTP 서버를 설치하고, Windows 호스트에서 접근하도록 포트포워딩까지 설정하는 방법을 단계별로 정리합니다.
1. WSL 환경 접속
- Windows 터미널(또는 PowerShell) 실행
- 설치된 배포판·버전 확인
wsl -l -v
- Ubuntu 배포판 실행
wsl -d Ubuntu
2. OpenSSH 서버 설치 (WSL 내부)
- 패키지 목록 업데이트
sudo apt update && sudo apt upgrade -y
- OpenSSH 서버 설치
sudo apt install openssh-server -y
3. sshd_config 설정
sudo vim /etc/ssh/sshd_config
필수 수정 항목:
- Port 22
- PasswordAuthentication yes
- PubkeyAuthentication yes
- Subsystem sftp internal-sftp
필요 시 PermitRootLogin no, ChrootDirectory 등 추가 설정 후 저장합니다.
4. SSH 서비스 시작 및 상태 확인
- SSH 서비스 시작
- 서비스 상태 확인
sudo service ssh status
5. WSL 내 로컬 접속 테스트
sftp <사용자>@localhost
- 비밀번호 또는 공개키 인증이 정상 작동하는지 검증합니다.
6. Windows ↔ WSL2 네트워크 연결 설정
WSL2는 NAT 환경이므로, Windows 호스트에서 WSL 내부 SSH 포트(22)를 외부로 노출해야 합니다.
1.WSL 내부 IP 확인
wsl hostname -I
2.PowerShell(관리자)에서 포트포워딩 추가
netsh interface portproxy add v4tov4 `
listenport=2222 listenaddress=0.0.0.0 `
connectport=22 connectaddress=<WSL_IP>
3.Windows 방화벽 규칙 추가
New-NetFirewallRule -DisplayName "WSL2 SSH" `
-Direction Inbound -LocalPort 2222 `
-Protocol TCP -Action Allow
7. 최종 접속 테스트
Windows 또는 외부 시스템에서 SFTP 접속:
sftp -P 2222 <사용자>@<Windows_호스트_IP>
이제 WSL 내부의 SFTP 서버로 파일 업·다운로드가 가능합니다.
** 첫 연결시 yes 선택
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ED9 key fingerprint is SHA256:
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no)?
이 단계에서 yes를 입력하면, 해당 키가 ~/.ssh/known_hosts 파일에 저장되어
다음 연결부터는 다시 묻지 않게 됩니다.
**그 외
openssh 설치 시 나오는 sshd 구성 파일 업데이트 시 선택 가이드
A new version (/tmp/tmp.25o6uLX6gk) of configuration file /etc/ssh/sshd_config is available, but the version
│ │ installed currently has been locally modified. │ │
│ │ What do you want to do about modified configuration file sshd_config? │ │
│ │ install the package maintainer's version
│ │ keep the local version currently installed
│ │ show the differences between the versions
│ │ show a side-by-side difference between the versions
│ │ show a 3-way difference between available versions
│ │ do a 3-way merge between available versions
│ │ start a new shell to examine the situation
SSHD 구성 파일 업데이트 시 선택 가이드
패키지 업그레이드 중 /etc/ssh/sshd_config 에 새 버전이 나오면 dpkg가 아래 옵션을 제시합니다:
- install the package maintainer’s version
- keep the local version currently installed
- show the differences between the versions
- show a side-by-side difference between the versions
- show a 3-way difference between available versions
- do a 3-way merge between available versions
- start a new shell to examine the situation
추천 절차
백업하기
모든 선택 전에 현 sshd_config 파일을 별도 백업하세요.
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
변경 사항 확인하기
직접 수정한 내용이 있다면, 새 패키지 버전과의 차이를 먼저 봅니다.
show the differences between the versions
또는
show a side-by-side difference between the versions
이렇게 하면 어떤 설정이 추가·삭제·변경됐는지 파악할 수 있습니다.
선택하기(기존 설정 유지)
keep the local version currently installed
완전 초기화해서 패키지 기본값으로 돌아가기
install the package maintainer's version
수동 병합(옵션: 로컬 설정과 새 버전을 동시에 반영)
do a 3-way merge between available versions
서비스 재시작
선택이 완료되면 반드시 SSHD를 재시작하세요.
sudo service ssh restart
요약
- 설정을 유지하려면 “keep the local version”
- 기본값으로 재설치하려면 “install the package maintainer’s version”
- 두 설정을 비교하려면 “show the differences” 또는 “side-by-side difference”
- 백업 후에 선택하고, 완료 뒤 sudo service ssh restart 해주세요.
'OS > Windows' 카테고리의 다른 글
| 포트포워딩 (0) | 2025.11.10 |
|---|---|
| Windows ↔ WSL2 네트워크 연결 설정 상세 (0) | 2025.07.15 |