리눅스 / 명령어 / 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 디렉토리에 복사한다.
  • 두 서버의 계정 암호를 다 묻는다.
같은 카테고리의 다른 글
Rocky Linux 10 / 방화벽 관리

Rocky Linux 10 / 방화벽 관리

Rocky Linux는 firewalld를 기본 방화벽으로 사용하며, firewall-cmd 명령어로 실시간 설정이 가능합니다. 포트나 서비스를 열고 닫거나, Zone을 통해 네트워크 접근을 세분화하여 관리할 수 있습니다. 설정은 일시적 또는 영구적으로 적용 가능합니다.

CentOS 7 / Let’s Encrypt에서 무료 SSL 인증서 발급 받는 방법

CentOS 7 / Let’s Encrypt에서 무료 SSL 인증서 발급 받는 방법

CentOS 7에서 Let’s Encrypt 인증서를 발급 받는 방법을 요약합니다. 환경 CentOS 7 Apache Web Server 설치 저장소 추가 yum install epel-release 설치 yum install python-certbot-apache 인증서 발급 abc.com 인증서 발급 certbot --apache -d abc.com abc.com과 www.abc.com 인증서 동시 발급 certbot --apache -d abc.com -d www.abc.com 인증서 갱신 Let’s Encrypt 인증서는 90일마다 갱신해야 합니다. certbot renew

CentOS 7 / firewall-cmd 명령어로 방화벽 관리하기

CentOS 7 / firewall-cmd 명령어로 방화벽 관리하기

CentOS의 방화벽 관리 데몬은 firewalld입니다. 설정은 firewall-cmd 명령어로 합니다. 방화벽 실행 여부 확인 firewall-cmd --state 실행 중이면 running, 실행 중이 아니면 not running을 출력합니다. 방화벽 다시 로드 firewall-cmd --reload 방화벽 설정 후 다시 로드해야 적용됩니다. 존(Zone) 출력하기 firewall-cmd --get-zones 존(zone) 목록을 출력합니다. firewall-cmd --get-default-zone 기본 존을 출력합니다. firewall-cmd --get-active-zones 활성화된 존을 출력합니다. 사용 가능한 서비스/포트 출력하기 firewall-cmd --list-all 사용 가능한 모든 서비스/포트 목록을 출력합니다. firewall-cmd --zone=public --list-all public 존에 ...

리눅스 / 하드디스크 파디션 만들기, 포맷하기, 마운트하기

리눅스에서 하드디스크 파티션 만들고, 포맷 하고, 마운트 하는 방법을 요약한다. 장착된 하드디스크 확인하기 ls 명령어로 컴퓨터에 장착된 하드디스크 정보를 출력할 수 있다. /dev/sda, /dev/sdb 등이 하드디스크, /dev/sda1 등이 파티션이다. # ls -l /dev/sd* brw-rw----. 1 root disk 8, 0 Oct 16 13:12 /dev/sda brw-rw----. 1 root disk 8, 1 Oct 16 13:12 /dev/sda1 brw-rw----. 1 ...

Ubuntu Server / 메모

MariaDB / 포트 변경 MariaDB의 기본 접속 포트는 3306입니다. 이를 다른 포트로 변경하고 싶다면 /etc/mysql/mariadb.conf.d/50-server.cnf를 수정합니다. port = 3306 을 찾아서 원하는 포트로 변경한 후 저장합니다. 그리고 MariaDB를 재시작합니다. service mysql restart MariaDB / Can't connect to MySQL server on ... (10061) 다음과 같은 에러를 만났다면... Can't connect to MySQL server on ... (10061) /etc/mysql/mariadb.conf.d/50-server.cnf에 있는 bind-address = 127.0.0.1 를 ...

Ubuntu 24.04 / 언어 변경하는 방법

현재 언어 확인하기 locale 명령어로 현재 언어를 확인할 수 있다. # locale LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= 언어 추가하기 사용 가능한 언어는 locale -a로 확인할 수 있다. # locale -a C C.utf8 en_US.utf8 POSIX 예를 들어 한국어를 추가하고 싶다면 아래와 같이 명령한다. # apt install language-pack-ko locale -a로 설치 확인을 한다. # locale -a C C.utf8 en_US.utf8 ko_KR.utf8 POSIX 언어 변경하기 다음과 같이 명령하면 사용하는 언어가 한국어로 바뀐다. update-locale LANG=ko_KR.utf8 로그아웃 후 다시 로그인하거나, 컴퓨터를 다시 시작하면 ...

리눅스 / 명령어 / 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 옵션으로 출력 ...

Rocky Linux 9 / SSH / 포트 변경하는 방법

Rocky Linux 9 / SSH / 포트 변경하는 방법

SSH는 22 포트를 사용한다. 알려진 포트이므로 다른 포트로 변경하는 것이 보안상 좋다. Rocky Linux 9에서 SSH 포트 변경하는 방법은 다음과 같다. 포트를 1980으로 바꾼다고 가정한다. /etc/ssh/sshd_config에서 다음의 코드를... #Port 22 다음으로 변경한다. Port 1980 SELINUX가 활성화되어 있다면 다음과 같이 명령하여 1980 포트를 사용할 수 있게 만든다. semanage port -a -t ssh_port_t -p tcp 1980 만약 다음과 같은 ...

Ubuntu 24.04 Server / root 계정으로 로그인할 수 있게, ssh 접속할 수 있게 설정하는 방법

Ubuntu는 설치할 때 일반 사용자 계정만 만들고, 관리자 권한이 필요할 때는 sudo를 이용한다. 만약 보안에 문제가 없는 경우라면 root 계정으로 로그인하는 게 작업하는 게 편하다. root 계정으로 로그인할 수 있게 설정하는 방법 일반 사용자 계정으로 로그인한다. 다음과 같이 명령하여 root 계정의 비밀번호를 만들면 root 계정으로 로그인할 수 있다. # sudo passwd root root 계정으로 ssh ...

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

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