전체 치트시트

SSH & OpenSSH 명령어 치트시트

OpenSSH 빠른 참조: 연결, 키 관리, 사용자 설정 파일, 파일 전송(scp/rsync/sshfs), 포트 포워딩과 점프 호스트 — 자주 쓰는 옵션과 실전 예시까지 정리했습니다.

명령어 26개

연결

ssh <user>@<host>

원격 호스트에 인터랙티브 SSH 세션을 엽니다.

-p PORT; -i identity_file; -l user (user@ 보다 우선); -E logfile 디버그; -v / -vv / -vvv 상세 수준

ssh -p 2222 [email protected]
ssh <user>@<host> '<cmd>'

원격 호스트에서 단일 비대화형 명령을 실행합니다.

ssh ops@db1 'sudo systemctl status postgresql'
ssh -J <jumphost>

SSH 연결을 점프 호스트(ProxyJump) 경유로 보냅니다.

-J user1@jump1:2222,user2@jump2; -o ProxyCommand=ssh -W ...

ssh -J [email protected] db1.private -i ~/.ssh/db1_key
ssh -N -L <l:r> -f <host>

셸을 열지 않고 백그라운드로 로컬 포트 포워딩. -L local:remote.

-N 원격 명령 없음; -f 백그라운드; -L 8080:localhost:80; -g 원격 측에서 로컬 측 연결 허용

ssh -N -L 5432:localhost:5432 -f db1 && psql -h localhost
ssh -N -R <r:localhost:l>

리버스 터널 — 원격 측에 포트를 열어 로컬 포트로 다시 보냅니다.

-N; -f; -R 8080:localhost:3000; GatewayPorts yes (서버 설정)

ssh -N -R 8080:localhost:3000 [email protected]
ssh -D <lport>

SSH 서버를 통해 로컬 측에 SOCKS 프록시를 구성합니다.

-C 압축; -q quiet; -D 1080

ssh -D 1080 -q -N tunnel.example.com && curl --proxy socks5h://localhost:1080 https://ifconfig.me
ssh -A <user>@<host>

로컬 ssh-agent 를 원격 호스트로 포워딩(SSH 체이닝).

-A agent forward; -a 비활성화

ssh -A ops@bastion && ssh internal-db # uses your local keys
ssh -o <key>=<value>

호출별 SSH 옵션을 전달합니다(설정 파일에 적을 필요 없는 일회성 변경에 유용).

StrictHostKeyChecking=no; UserKnownHostsFile=/dev/null (보안상 데모용만); RequestTTY=force

ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected]
ssh -F <configfile>

대안 ssh_config 파일을 사용합니다(프로젝트/고객별 설정에 유용).

-F path; -G 연결 없이 설정을 파싱해 출력

ssh -F ~/.ssh/config.work -G devbox | grep -E 'hostname|user'

ssh-keygen -t ed25519 -C '<email>'

최신의 간결한 ED25519 키 쌍을 생성합니다(RSA 보다 권장).

-t ed25519|rsa|ecdsa; -b bits; -C comment; -f output_path; -N 'passphrase'; -q quiet

ssh-keygen -t ed25519 -C 'you@work' -f ~/.ssh/work_ed25519 -N ''
ssh-keygen -lf <pubkey>

공개 키의 fingerprint 와 길이를 표시합니다(SSH 배너 감사).

-E md5|sha256|shake256; -l 목록; -i stdin 에서 읽기

ssh-keygen -lf ~/.ssh/id_ed25519.pub -E sha256
ssh-keygen -R <host>

known_hosts 에서 호스트 키를 제거합니다(서버가 재구축/키 교체된 후).

-R '[host]:port' 비표준 포트 지원

ssh-keygen -R '[bastion.example.com]:2222'
ssh-copy-id <user>@<host>

원격 authorized_keys 에 공개 키를 설치합니다(패스워드 인증 필요).

-i identity.pub; -p PORT; -o options

ssh-copy-id -i ~/.ssh/work_ed25519.pub -p 2222 deploy@bastion
ssh-add [path]

실행 중인 ssh-agent 에 개인 키를 추가합니다(패스프레이즈를 매번 입력하지 않아도 됨).

-l fingerprint 목록; -D 모두 삭제; -d path 삭제; -t N lifetime

eval $(ssh-agent) && ssh-add ~/.ssh/work_ed25519 && ssh-add -l
ssh-keyscan <host>

원격 호스트 키를 출력합니다(known_hosts 사전 등록 / 부트스트랩 용).

-t rsa|ed25519|ecdsa; -p PORT

ssh-keyscan -t ed25519 -p 2222 bastion.example.com >> ~/.ssh/known_hosts

설정 파일

~/.ssh/config

사용자별 SSH 설정 — 호스트, 별칭, identity, 점프 호스트, keepalive 선언.

Host alias; HostName real; User; Port; IdentityFile; PreferredAuthentications; AddKeysToAgent yes; ServerAliveInterval 30; IdentitiesOnly yes; ProxyJump / ProxyCommand; LocalForward / RemoteForward; ControlMaster auto / ControlPath / ControlPersist

Host bastion HostName bastion.example.com Port 2222 User ops IdentityFile ~/.ssh/work_ed25519 Host db* ProxyJump bastion User ubuntu

파일 전송

scp <src> <dest>

SSH 로 호스트 간 파일을 복사합니다(레거시지만 어디서나 사용 가능).

-r 재귀; -P PORT; -i identity; -C 압축; -p mode/time 보존; -l 대역폭 제한 (Kbit/s)

scp -P 2222 -r dist/ [email protected]:/srv/app/releases/1.4.2/
rsync -avz -e ssh <src> <dest>

델타 동기화로 미러링/복사 — 큰 트리를 반복 전송할 때 훨씬 빠릅니다.

-a 아카이브; -v verbose; -z 압축; -P 부분저장 + 진행률; --delete 미러; --exclude; --dry-run; -e ssh -p 2222

rsync -avz -e 'ssh -p 2222' ./build/ ops@bastion:/srv/app/current/
sshfs <user>@<host>:<path> <mount>

원격 파일 시스템을 SSH(FUSE) 로 마운트 — 로컬 도구로 원격 파일을 편집합니다.

-p PORT; -o reconnect; -o transform_symlinks; -C 압축

sshfs ops@bastion:/srv/app ./remote -o reconnect,transform_symlinks
sftp <user>@<host>

SSH 서브시스템으로 인터랙티브/스크립트 기반 파일 전송.

sftp -i id -P port; commands: get / put / sync / ls / lls / cd / lcd / chmod

sftp ops@bastion <<'EOF' mkdir /srv/app/releases/1.4.2 put -r dist/* /srv/app/releases/1.4.2/ EOF

문제 해결

ssh -vvv <host>

연결 추적: KEX, 인증, 채널 설정. "왜 실패하지?" 에 최적.

-v / -vv / -vvv; -E file 파일로 기록

ssh -vvv -E /tmp/ssh.dbg ops@bastion 2>&1 | grep -E 'Authentications|method|Permission denied'
ssh-keygen -y -f <private>

개인 키로부터 공개 키를 유도합니다(개인 키만 있을 때).

-f file; -E hash algorithm

ssh-keygen -y -f ~/.ssh/id_ed25519 > /tmp/derived.pub && diff ~/.ssh/id_ed25519.pub /tmp/derived.pub && echo OK
ssh -o ConnectTimeout=<N> -o ConnectionAttempts=<K>

불안정한 네트워크나 미리 워밍업된 점프 호스트에 맞춰 연결 타임아웃/재시도 조정.

ssh -o ConnectTimeout=5 -o ConnectionAttempts=2 ops@bastion
ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=3

NAT/방화벽 사이에서 유휴 SSH 연결을 살려 둡니다.

ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -L 5432:db:5432 -N ops@bastion

신뢰 포워딩

ssh -W %h:%p <proxy>

ProxyCommand 로 체이닝 — ProxyJump 의 구식 대안.

ProxyCommand ssh -W %h:%p myjumphost nc -q0 %h %p

ssh -o ProxyCommand='ssh -W %h:%p bastion.example.com' internal-db

유지 보수

ssh -O stop / ssh -M -S <sock>

ControlMaster — 여러 터미널에서 단일 SSH 세션을 공유해 속도를 높입니다.

-M master mode; -S socket path; -O check|forward|exit

ssh -M -S ~/.ssh/cm-%h bastion; ssh -S ~/.ssh/cm-%h bastion -O check

치트시트 버전 1.0.0

OpenSSH 9.0+ 대응