ssh 사용법
SSH 키 생성
ssh-keygen -t ed25519 -N "" -C "hhk7734@gmail.com" -f <path>
ssh-keygen -t rsa -b 2048 -N "" -C "hhk7734@gmail.com" -f <path>
config
~/.ssh/config
또는 /etc/ssh/ssh_config
파일에 아래 설정을 추가할 수 있습니다.
Host <alias>
HostName <host>
User <user>
PreferredAuthentications publickey
IdentityFile <path>
AddKeysToAgent yes
ssh agent 실행
eval "$(ssh-agent -s)"
.zshrc
plugins=(
ssh-agent
)
로컬에 프라이빗 키 등록
ssh-add ~/.ssh/<private>
접속할 곳에 퍼블릭 키 등록
ssh-copy-id -i ~/.ssh/<public> <remote>
SCP
source를 target으로 보낼 수 있는 명령어입니다.
원격지의 경우 <user>@<ip>:<path>
로 구성됩니다.
scp [options] <source> <target>
파일 권한
sudo chmod 700 ~/.ssh
sudo chmod 600 ~/.ssh/*
danger
파일 접근 권한은 로컬과 원격 모두 설정되어 있어야 합니다.
SSH Tunnel
/etc/ssh/sshd_config
AllowTcpForwarding yes
PermitTunnel yes
ssh -f -N \
-L <localPort>:<host>:<port> \
-p <tunnelPort> <tunnelUser>@<tunnelHost>
암호 입력이 나오면 <tunnelHost>
의 암호를 입력합니다.
lsof -i4 -P | grep -i "listen" | grep <localPort>
nc -zv 127.0.0.1 <localPort>
ps -lef | grep ssh | grep "\-L \?<localPort>" \
| awk '{print $4}' | xargs kill -9