본문 바로가기
개발/아키텍처

로컬에서 리눅스에 파일을 업/다운로드 할 수 있는 scp 명령어에 대해 알아보자

by Devsong26 2021. 7. 9.

git을 clone할 때는 서버에서 웹에 접속하여 데이터를 다운로드를 받는다.

 

어떤 경우는 로컬에서 리눅스 서버에 파일을 업로드 혹은 다운로드 해야 할 때가 있다.

윈도우 사용할 때는 파일지라를 사용하였지만, 맥을 사용하다 보니 커맨드가 더 익숙해져서 

어떻게 하면 파일을 올릴 수 있을지 알아보고 scp라는 명령어를 알게 됐다.

 

scp 란?

Secure copy protocol(SCP) is a means of securely transferring 
computer files between a local host and a remote host or between two remote hosts.
It is based on the Secure Shell (SSH) protocol.

출처: https://en.wikipedia.org/wiki/Secure_copy_protocol

 

기본적인 사용법은 아래와 같다.

# 로컬에서 서버로 파일 업로드할 때
scp LocalSourceFile user@remotehost:directory/TargetFile

# 로컬에서 서버로 파일 다운로드할 때
scp user@remotehost:directory/TargetFile LocalSourceFile

 

하지만 필자의 경우, pem 파일을 사용하므로 -i 옵션을 사용한다.

-i 옵션의 설명은 아래와 같다.

-i identity_file
Selects the file from which the identity (private key) for public key authentication is read.

 

예제는 아래와 같다.

# 로컬에서 서버로 파일 업로드할 때
scp -i PemFilePath LocalSourceFile user@remotehost:directory/TargetFile

# 로컬에서 서버로 파일 다운로드할 때
scp -i PemFilePath user@remotehost:directory/TargetFile LocalSourceFile

 

도움이 되셨다면 "좋아요" 부탁드립니다.

 


더 많은 내용을 보시려면 아래를 참고하세요.


Reference

 

scp(1): secure copy - Linux man page

scp(1) - Linux man page Name scp - secure copy (remote file copy program) Synopsis scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [ [user@]host1:]file1 ... [ [user@]host2:]file2 Descriptio

linux.die.net

 

블로그의 다른 글

 

Ubuntu 메모리 사용량 줄이기 - 캐시 메모리 클리어

안녕하세요! 초보 개발자 슈브로포입니다. 저는 서버 OS로 Ubuntu 18.04LTS를 주로 사용합니다. 익숙해서 그런지 Centos는 어색하더라고요 :) AWS에서 Ubuntu AMI를 선택하여 EC2를 생성하여 사용하다 보면

developer-syubrofo.tistory.com

 

Ubuntu Server Settings

Bitbucket git settings - ssh key settings cd ~/.ssh ssh-keygen -t rsa -C your-email - create bitbucket config file vim ~/.ssh/config # vim mode Host bitbucket.org HostName bitbucket.org IdentityFile..

developer-syubrofo.tistory.com