리눅스 / 명령어 / scp

scp는 ssh 프로토콜을 이용하여 파일을 송수신하는 명령어이다.

  • local → remote
  • remote → local
  • remote → remote

모두 가능하다.

local → remote

파일 복사

# scp a.txt root@192.168.3.211:/temp/a.txt
root@192.168.3.211's password:
  • 명령어를 실행한 디렉토리에 있는 a.txt 파일을 192.168.3.211 컴퓨터에 root 계정으로 연결하여 복사한다.
  • 원격 컴퓨터에 /temp 디렉토리가 없으면 복사되지 않는다.
  • 원격 컴퓨터에 /temp 디렉토리가 있으면 a.txt로 복사된다. a.txt 파일이 이미 있다면 덮어쓴다.
  • root 계정의 비밀번호를 입력해야 진행된다.

처음 접속하는 거라면 아래와 같은 메시지가 나올 수 있다. yes 또는 y를 입력하고 진행한다.

The authenticity of host '192.168.3.211 (192.168.3.211)' can't be established.
ED25519 key fingerprint is SHA256:CWaawH0/RAuNqbjiXuu4WeYsqo+9JdOJi10uMBuXvl4.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
# scp a.txt root@192.168.3.211:/temp
  • /temp 디렉토리가 없으면 a.txt 파일이 temp 파일로 복사한다.
  • /temp 디렉토리가 있으면 /temp/a.txt 파일로 복사한다.
# scp a.txt root@192.168.3.211:/temp/
  • /temp 디렉토리가 없으면 복사되지 않는다.
  • /temp 디렉토리가 있으면 /temp/a.txt 파일로 복사한다.
# scp b.txt c.txt root@192.168.3.211:/temp
  • 여러 파일을 동시에 복사할 수 있다.
# scp b.txt *.txt root@192.168.3.211:/temp
  • 와일드카드 등을 사용할 수 있다.
# scp -P 2000 a.txt root@192.168.3.211:/temp
  • ssh 포트가 22가 아니라면 -P 옵션으로 지정할 수 있다.

디렉토리 복사

# scp -r abc root@192.168.3.211:/temp/
  • 디렉토리를 복사할 때는 -r 옵션을 붙인다.
  • /temp 디렉토리가 없으면 복사되지 않는다.
  • /temp 디렉토리가 있으면 /temp/abc로 복사한다.
# scp -r abc root@192.168.3.211:/temp
  • /temp 디렉토리가 없으면 /temp 디렉토리를 만들고, 그 안에 abc 디렉토리 안의 파일 등을 복사한다.
  • /temp 디렉토리가 있으면 /temp 안에 abc 디렉토리를 복사한다.

remote → local

# scp -r root@192.168.3.211:/temp/abc ./
  • 192.168.3.211 컴퓨터에 root 계정으로 연결하여, /temp/abc 디렉토리를 현재 디렉토리로 복사한다.

remote → remote

# scp root@192.168.3.211:/temp/a.txt root@192.168.3.202:/temp/
root@192.168.3.202's password:
root@192.168.3.211's password:
  • 192.168.3.211에 있는 /temp/a.txt 파일을 192.168.3.202의 /temp 디렉토리에 복사한다.
  • 두 서버의 계정 암호를 다 묻는다.
같은 카테고리의 다른 글

리눅스 - 오픈 소스의 선두 주자

리눅스 개요 리눅스(Linux)는 유닉스(Unix) 운영체제의 계열에 속하는 자유롭고 오픈 소스인 운영체제입니다. 리눅스 커널은 1991년 핀란드의 대학생이었던 리누스 토르발스(Linus Torvalds)에 의해 처음 개발되었으며, GNU 프로젝트의 일환으로 개발된 다양한 소프트웨어와 결합되어 완전한 운영체제를 구성합니다. 오늘날 리눅스는 서버, 데스크탑, 모바일 장치, 임베디드 시스템 등 다양한 플랫폼에서 널리 사용되고 있습니다. 리눅스의 역사 리눅스의 역사는 1991년으로 거슬러 올라갑니다. ...

Ubuntu 16.04 / SASS 설치하는 방법

우분투 16.04에 SASS를 설치하는 방법은 두 가지가 있습니다. 방법 1 apt install ruby-sass 방법 2 apt install ruby gem install sass 설치되었는지 확인하는 방법 sass -v SASS 버전이 출력되면 제대로 설치된 것입니다. Sass 3.4.23 (Selective Steve) 참고 최신 버전의 SASS를 사용하고 싶다면 방법 2로 설치합니다.

Ubuntu 20.04 Server / 설치하기

Ubuntu 20.04 Server / 설치하기

다운로드 Ubuntu Server 다운로드 페이지는 다음과 같다. https://ubuntu.com/download/server 최신 버전에 대한 안내가 주로 있으므로, 구버전을 다운로드하고 싶다면 아래 링크가 편하다. https://mirror.kakao.com/ubuntu-releases/ 가상 머신에 설치한다면 다운로드한 ISO 파일을 그대로 사용하면 되고, 물리 서버에 설치한다면 Rufus 같은 툴을 이용하여 부팅 USB를 만든다. 설치 설치 미디어로 부탕하고 잠시 기다리면 언어를 선택하는 화면이 나온다. 원하는 언어를 선택하고 엔터키를 누른다. 키보드 레이아웃을 선택한다. 네트워크 ...

리눅스 / chown, chmod / 파일 또는 디렉토리 소유자, 소유그룹, 권한 설정

chown과 chmod는 파일 및 디렉토리의 권한과 소유자를 관리하는 데 사용되는 Linux 명령어입니다. 정보 확인 ls 명령어에 -l 옵션을 붙여서 파일 또는 디렉토리의 권한과 소유자(그룹)을 확인할 수 있습니다. 제일 앞에 있는 문자는 디렉토리인지 파일인지는 나타냅니다. d는 디렉토리라는 뜻이고, -는 파일이라는 뜻입니다. 그 다음 3개의 문자열은 소유자의 권한을, 그 다음 3개의 문자열은 소유그룹의 권한을, 그 다음 ...

CentOS 7 / ntp로 시간 동기화 하는 방법

CentOS 7 / ntp로 시간 동기화 하는 방법

리눅스가 OS인 서버의 시간과 실제 시간을 동기화하는 방법 중의 하나는 ntp를 이용하는 것입니다. CentOS 7에 ntp를 설치하고 설정하는 방법을 요약합니다. ntp 설치 yum install ntp 동기화할 서버 주소 가까운 곳에 있는 시간 서버를 사용하는 게 좋습니다. (하지만, 설정을 변경하지 않아도 큰 문제는 없습니다.) 서버 주소는 http://www.pool.ntp.org/에서 구할 수 있습니다. 지역을 아시아로 했을 때의 서버 주소는 다음과 같습니다. server 0.asia.pool.ntp.org server ...

Ubuntu 16.04 / 메모

PHP intl 설치 apt install php-intl service apache2 reoad APCu 설치 apt install php-apcu service apache2 reload

리눅스 / 커널 / 버전 확인하는 방법

리눅스 커널 버전을 확인하는 방법은 여러 가지가 있습니다. 그 중 자주 사용하는 방법 두 가지를 소개합니다. uname uname 명령어는 시스템 정보를 출력하는 데 사용됩니다. -r 옵션을 사용하여 커널 버전을 확인할 수 있습니다. # uname -r 6.8.0-35-generic hostnamectl hostnamectl 명령어는 시스템의 호스트 이름과 관련된 정보를 관리하고 표시합니다. 여기에는 커널 버전 정보도 포함됩니다. # hostnamectl Static hostname: ubuntu-24-01 ...

리눅스 / 로그아웃 명령어, 재부팅 명령어, 종료 명령어

로그아웃 명령어 # logout # exit 재부팅 명령어 즉시 재부팅 # reboot # shutdown -r now # init 6 일정 시간 또는 일정 시간 후 재부팅 10분 후 재부팅 # shutdown -r 10 12시에 재부팅 # shutdown -r 12:00 취소 # shutdown -c 종료 명령어 즉시 종료 # poweroff # shutdown -h now # shutdown -P now # halt -p # init 0 일정 시간 또는 일정 시간 후에 종료 10분 후에 종료 # ...

리눅스 / 명령어 / which, whereis, locate / 명령어 위치 찾기

명령어의 위치를 찾을 때 사용할 수 있는 명령어에는 which, whereis, locate가 있다. 명령어의 위치만 찾을 때는 which를 사용하고, 관련된 파일들의 위치까지 찾을 때는 whereis나 locate를 사용한다. which 명령어로 find 명령어를 찾는다. # which find /usr/bin/find whereis 명령어로 find 명령어를 찾는다. # whereis find find: /usr/bin/find /usr/share/man/man1/find.1.gz locate 명령어로 find 명령어를 찾는다. # locate find /usr/bin/find /usr/bin/find2perl /usr/bin/findmnt /usr/bin/nl-link-ifindex2name /usr/bin/nl-link-name2ifindex /usr/bin/oldfind /usr/lib64/python2.7/modulefinder.py /usr/lib64/python2.7/modulefinder.pyc /usr/lib64/python2.7/modulefinder.pyo /usr/sbin/btrfs-find-root /usr/sbin/findfs /usr/share/bash-completion/completions/findmnt /usr/share/doc/findutils-4.5.11 /usr/share/doc/findutils-4.5.11/AUTHORS /usr/share/doc/findutils-4.5.11/COPYING /usr/share/doc/findutils-4.5.11/ChangeLog /usr/share/doc/findutils-4.5.11/NEWS /usr/share/doc/findutils-4.5.11/README /usr/share/doc/findutils-4.5.11/THANKS /usr/share/doc/findutils-4.5.11/TODO /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_find.py /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_stop_find.py /usr/share/info/find-maint.info.gz /usr/share/info/find.info.gz /usr/share/locale/be/LC_MESSAGES/findutils.mo /usr/share/locale/bg/LC_MESSAGES/findutils.mo /usr/share/locale/ca/LC_MESSAGES/findutils.mo /usr/share/locale/cs/LC_MESSAGES/findutils.mo /usr/share/locale/da/LC_MESSAGES/findutils.mo /usr/share/locale/de/LC_MESSAGES/findutils.mo /usr/share/locale/el/LC_MESSAGES/findutils.mo /usr/share/locale/eo/LC_MESSAGES/findutils.mo /usr/share/locale/es/LC_MESSAGES/findutils.mo /usr/share/locale/et/LC_MESSAGES/findutils.mo /usr/share/locale/fi/LC_MESSAGES/findutils.mo /usr/share/locale/fr/LC_MESSAGES/findutils.mo /usr/share/locale/ga/LC_MESSAGES/findutils.mo /usr/share/locale/gl/LC_MESSAGES/findutils.mo /usr/share/locale/hr/LC_MESSAGES/findutils.mo /usr/share/locale/hu/LC_MESSAGES/findutils.mo /usr/share/locale/id/LC_MESSAGES/findutils.mo /usr/share/locale/it/LC_MESSAGES/findutils.mo /usr/share/locale/ja/LC_MESSAGES/findutils.mo /usr/share/locale/ko/LC_MESSAGES/findutils.mo /usr/share/locale/lg/LC_MESSAGES/findutils.mo /usr/share/locale/lt/LC_MESSAGES/findutils.mo /usr/share/locale/ms/LC_MESSAGES/findutils.mo /usr/share/locale/nl/LC_MESSAGES/findutils.mo /usr/share/locale/pl/LC_MESSAGES/findutils.mo /usr/share/locale/pt/LC_MESSAGES/findutils.mo /usr/share/locale/pt_BR/LC_MESSAGES/findutils.mo /usr/share/locale/ro/LC_MESSAGES/findutils.mo /usr/share/locale/ru/LC_MESSAGES/findutils.mo /usr/share/locale/rw/LC_MESSAGES/findutils.mo /usr/share/locale/sk/LC_MESSAGES/findutils.mo /usr/share/locale/sl/LC_MESSAGES/findutils.mo /usr/share/locale/sr/LC_MESSAGES/findutils.mo /usr/share/locale/sv/LC_MESSAGES/findutils.mo /usr/share/locale/tr/LC_MESSAGES/findutils.mo /usr/share/locale/uk/LC_MESSAGES/findutils.mo /usr/share/locale/vi/LC_MESSAGES/findutils.mo /usr/share/locale/zh_CN/LC_MESSAGES/findutils.mo /usr/share/locale/zh_TW/LC_MESSAGES/findutils.mo /usr/share/man/man1/find.1.gz /usr/share/man/man1/find2perl.1.gz /usr/share/man/man1/oldfind.1.gz /usr/share/man/man8/btrfs-find-root.8.gz /usr/share/man/man8/findfs.8.gz /usr/share/man/man8/findmnt.8.gz locate 명령어는 -n 옵션으로 출력 ...

Ubuntu 22.04 Server / root 계정으로 로그인하는 방법, root 계정으로 ssh 접속하는 방법

Ubuntu는 설치할 때 일반 사용자 계정만 만듭니다. 관리자 권한이 필요할 때는 sudo를 이용하죠. 그런데 공부를 위해 혼자만 사용하거나, 여러 가지 이유로 보안에 문제가 없는 경우 root 계정으로 로그인해서 작업하는 게 편합니다. root 계정으로 로그인 하는 방법 일반 사용자 계정으로 로그인합니다. 다음과 같이 명령하여 root 계정의 비밀번호를 만들면 root 계정으로 로그인할 수 있습니다. # sudo ...