[Linux] 리눅스 백그라운드 (Background) 환경에서 scp 수행 방법 및 유용한 명령어

 정보

  • 업무명     : 백그라운드 (Background) 환경에서 scp 수행 방법 및 유용한 명령어

  • 작성자     : 이상호

  • 작성일     : 2021-01-27

  • 설   명      :

  • 수정이력 :

 

 내용

[개요]

  • 안녕하세요? 기상 연구 및 웹 개발을 담당하고 있는 해솔입니다.

  • 리눅스에서 로컬 호스트와 원격 호스트간에 파일을 전송하는 경우에는 scp를 사용합니다.

  • 이러한 scp 명령어는 SSH 프로토콜을 사용하여 안전하게 파일 전송을 할 수 있습니다.

  • 오늘 포스팅에서는 백그라운드 (Background) 환경에서 scp 수행 방법 및 유용한 명령어를 소개합니다.

 

etc-image-0

 

[특징]

  • 리눅스에서 원격/로컬에서 파일 복사를 위해 scp 기술이 요구되며 이 프로그램은 이러한 목적을 달성하기 위한 기술서

 

[기능]

  • 백그라운드 환경에서 scp 수행

  • 유용한 명령어

 

[활용 자료]

  • 없음

 

[자료 처리 방안 및 활용 분석 기법]

  • 없음

 

[명세]

  • 없음

 

[사용법]

  • 없음

 

[사용 OS]

  • Windows 10

 

[사용 언어]

  • Linux (CentOS v7.3)

  • VMware Workstation Pro v16

 

 세부 내용

[백그라운드 환경에서 scp 수행]

  • 백그라운드 환경에서 리눅스 (Linux) 명령을 실행하려면 다음과 같이 nohup을 사용

nohup CMD &

 

  • 그러나 scp 명령의 문제점은 비밀번호를 물음 (암호 인증이 사용되는 경우)

  • 따라서 다음과 같은 순서대로 진행 필요

nohup scp fileToCopy user@server:/path/to/copy/the/file > nohup.out 2>&1

 

  • <ctrl + z> 단축키통해 일시 중단 그리고 백그라운드 환경으로 이동

bg

 

  • nohup 명령 재 수행

nohup scp fileToCopy user@server:/path/to/copy/the/file > nohup.out 2>&1

 

[유용한 명령어]

  • 로컬 (a.txt)에서 원격 (/remote/directory)으로 복사

scp a.txt username@remote.example.com:/remote/directory

 

  • 원격 (/remote/directory/a.txt)에서 로컬 (/local/directory)로 복사

scp username@remote.example.com:/remote/directory/a.txt /local/directory

 

  • 로컬 하위 디렉토리를 원격으로 복사

    • 옵션 -r : 하위 디렉터리

scp -r local_dir username@remote.example.com:/remote/directory

 

  • 키 인증을 통해 원격으로 복사

    • 옵션 -i : 키 경로를 지정

scp -i ~/.ssh/id_rsa a.txt username@remote.example.com:/remote/directory

 

  • 포트 번호를 지정하여 원격 복사

    • 옵션 -P : 포트를 지정

scp -P 2222 a.txt username@remote.example.com:/remote/directory

 

  • 여러 파일을 원격으로 복사

  • 로컬 (a.txt, b.jpg)에서 원격으로 복사

scp a.txt b.jpg username@remote.example.com:/remote/directory

 

  • 로컬 (a.txt, b.txt, c.txt)에서 원격으로 복사

scp {a,b,c}.txt username@remote.example.com:/remote/directory

 

  • 로컬 (현재 디렉토리에 있는 모든 .txt 파일)에서 원격으로 복사

scp *.txt username@remote.example.com:/remotedirectory

 

  • 여러 파일을 로컬로 복사

  • 원격 (a.txt, b.jpg)에서 로컬로 복사

scp username@remote.example.com:/remote/directory/\{a.txt, b.jpg\} .

 

  • 원격 (a.txt, b.txt, c.txt)에서 로컬로 복사

scp username@remote.example.com:/remote/directory /\{a,b,\}.txt .

 

  • 원격 (디렉토리에 있는 모든 .txt 파일)에서 로컬로 복사

scp username@remote.example.com:/remote/directory/*.txt .

 

 참고 문헌

[논문]

  • 없음

[보고서]

  • 없음

[URL]

  • 없음

 

 문의사항

[기상학/프로그래밍 언어]

  • sangho.lee.1990@gmail.com

[해양학/천문학/빅데이터]

  • saimang0804@gmail.com