Skip to main content

SSH


ν‚€ 생성​

ssh-keygen -t ed25519 -C "your_email@example.com"
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

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에 μΆ”κ°€ν•˜λ©΄ agentλ₯Ό μžλ™μœΌλ‘œ μ‹€ν–‰ν•©λ‹ˆλ‹€.

env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }

agent_load_env

# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2=agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi

unset env

ν‚€ 등둝​

ssh-add ~/.ssh/<id file>

퍼블릭 ν‚€ 접속할 곳에 등둝​

ssh-copy-id -i ~/.ssh/<id file>.pub <remote>

SCP​

sourceλ₯Ό target으둜 보낼 수 μžˆλŠ” λͺ…λ Ήμ–΄μž…λ‹ˆλ‹€.

μ›κ²©μ§€μ˜ 경우 \<user>@\<ip>:\<path> 둜 κ΅¬μ„±λ©λ‹ˆλ‹€.

scp [options] <source> <target>

파일 κΆŒν•œβ€‹

sudo chmod 700 ~/.ssh
sudo chmod 400 ~/.ssh/*

Reference​