Skip to main content

SSH and SCP


Installation

sudo apt install -y openssh-server openssh-client ssh-askpass

ํ‚ค ์ƒ์„ฑ

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

.ssh/config

Host <alias>
HostName <host>
User <user>
PreferredAuthentications publickey
IdentityFile <path>

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-add -l

ํผ๋ธ”๋ฆญ ํ‚ค ์ ‘์†ํ•  ๊ณณ์— ๋“ฑ๋ก

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