[Linux] scp 명령어로 (로컬↔서버) 파일 전송
scp는 SecureCopy의 약자로, 원격서버에 있는 파일과 폴더를 전송하거나 가져오기 위해 사용하는 명령어이다. ssh 원격 접속 프로토콜을 기반으로 하며, ssh와 동일한 22번 포트를 이용하기 때문에 password/identity file을 이용해 안전하게 송수신 할 수 있다.
local→remote
, remote→local
, remote→remote
로의 송수신이 모두 가능하다.
> scp [options] [source] [target]
# source : 파일을 보낼 주소# target : 파일을 받을 주소
보낼 파일의 주소로 파일명
만 명시했더니 permission denied
가 떴다. 이후 절대경로로 변경해주니 파일이 잘 전송된 것을 확인 할 수 있었다.
> scp [전송할 파일 경로] [유저명]@[IP주소]:[받을 경로]
EX) 로컬의 /home/example.txt 파일을 원격지의 /home/test 디렉토리로 전송
> scp /home/example.txt [email protected]:/home/test
> scp [유저명]@[IP주소]:[전송할 파일 경로] [받을 경로]
EX) 원격지의 /home/test.txt 파일을 로컬의 /home/example 디렉토리로 전송
> scp [email protected]:/home/test.txt /home/example
> scp [유저명]@[IP주소]:[전송할 파일 경로] [유저명]@[IP주소]:[받을 경로]
EX) A 원격지의 /home/test.txt 파일을 B 원격지의 /home/example 디렉토리로 전송
> scp [email protected]:/home/test.txt [email protected]:/home/example
r
: 폴더를 복사할 때 사용(전송 대상을 폴더로 지정). 모든 폴더들을 재귀적으로 복사함.P
: ssh 포트 지정i
: identity file을 지정해서 사용(identity file 경로를 지정)> ex) scp -i ~/.ssh/dhj-server-private ~/example.txt [email protected]:/home/test
v
: 상세내용을 보면서 디버깅 할 때 사용(verbose 모드)