C.W.K.
Stream
Lesson 09 of 12 · published

다른 포트의 SSH

~15 min · ssh-port, sshd-config, non-standard-port

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

포트 22 는 관습이지 법 아님

SSH 기본 포트 22 인데, 데몬은 알려준 어느 포트든 기꺼이 listen. SSH 를 22 에서 옮기는 거 진짜 보안 아니야 — port scan 으로 몇 초 안에 찾아 — 하지만 public 서버에선 자동화된 brute-force 노이즈 극적으로 줄여. 22 의 서버는 하루 수천 시도 보고; 2222 는 한 줌.

비기본 포트 연결

클라이언트 쪽 -p flag, ~/.ssh/configPort 지시자, scp-P flag (그래, 대문자 P — scp 가 짜증나게 다름).

서버 포트 변경

/etc/ssh/sshd_config 편집, Port 22 를 선택한 번호로, sshd 재시작. 방화벽이 필터링 중이면 새 포트 열고 (나중에) 22 닫아. 항상 기존 연결을 lifeline 으로 열어둬.

Code

클라이언트 쪽·bash
# Connect to a non-default port
ssh -p 2222 you_username@192.168.1.100

# In ~/.ssh/config — Track 3 covers this in depth
# Host office
#     HostName 192.168.1.100
#     Port 2222

# scp uses capital -P (because scp is petty)
scp -P 2222 file.txt you_username@192.168.1.100:/tmp/
서버 쪽 — listening 포트 변경·bash
# Edit the daemon config
sudo nano /etc/ssh/sshd_config
# Change:
#   #Port 22
# To:
#   Port 2222

# Validate the config BEFORE restarting
sudo sshd -t

# Restart
# Linux
sudo systemctl restart sshd
# macOS — toggle Remote Login off/on in System Settings

# Open the firewall on the new port (Linux ufw)
sudo ufw allow 2222/tcp
# (Track 8 has full firewall coverage)

External links

Exercise

테스트 머신 (유일한 원격 서버 아님) 에서 위 step 으로 SSH 포트를 2222 로. sudo sshd -t 먼저 검증. sshd 재시작. 새 터미널에서 ssh -p 2222 user@host 동작, ssh -p 22 user@host 안 함 확인. 보너스 — ~/.ssh/config 에 Host 항목 추가하고 Port 2222 적어서 매번 -p 안 쳐도 되게. 최종 포트 선택 아니면 끝나고 되돌려.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.