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

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

리눅스 / 명령어 / free / 메모리 사용량 확인하는 명령어

free는 메모리 사용량을 확인하는 명령어이다. free # free total used free shared buff/cache available Mem: ...

리눅스 / 명령어 / cal / 달력을 출력하는 명령어

cal은 달력을 출력하는 명령어이다. 아무 옵션 없이 사용하면 현재 날짜가 속한 달의 달력을 출력한다. cal October 2022 Su Mo Tu We Th Fr Sa 1 2 3 4 5 ...

리눅스 / 파일 또는 디렉토리 이름 바꾸는 방법

파일 이름 바꾸기 mv는 파일을 이동시키는 명령어이다. 이 명령어를 이용해서 파일 이름을 바꿀 수 있다. 예를 들어 다음은 abc.txt를 xyz.txt로 바꾼다. # mv abc.txt xyz.txt 디렉토리 이름 바꾸기 디렉토리 이름을 바꾸는 것도 파일 이름 변경과 같다. 다음은 abc 디렉토리의 이름을 xyz로 바꾼다. # mv abc xyz

리눅스 / 명령어 / rmdir / 빈 디렉토리 삭제하는 명령어

rmdir rmdir은 빈 디렉토리를 삭제하는 명령어이다. Remove the DIRECTORY(ies), if they are empty. 사용법 rmdir directory a 디렉토리를 삭제한다. # rmdir a  비어있다면 삭제를 하고, 그렇지 않다면 다음을 출력한다. rmdir: failed to remove ‘a’: Directory not empty rmdir --ignore-fail-on-non-empty directory 디렉토리가 비어있지 않아도 메시지를 출력하지 않는다. rmdir -v directory 현재 디렉토리 안에 있는 모든 비어있는 디렉토리를 삭제한다. v 옵션을 넣으면 작업 결과를 ...

리눅스 / 명령어 / cat / 파일 내용 출력하는 명령어

다음과 같은 두 개의 파일이 있다고 할 때 file1 1-1 1-2 1-3 file2 2-1 2-2 2-3 cat filename cat 뒤에 파일 이름을 넣으면 파일 안의 내용을 보여줍니다. # cat file1 1-1 1-2 1-3 파일 이름을 연달아 넣으면 연속하여 파일의 내용을 보여줍니다. # cat file1 file2 1-1 1-2 1-3 2-1 2-2 2-3 cat filename -n -n 옵션을 붙이면 줄번호를 보여줍니다. # cat -n file1 1 1-1 2 1-2 3 1-3 # cat -n file1 file2 1 1-1 2 1-2 3 1-3 4 2-1 5 2-2 6 ...

리눅스 / 명령어 / cd / 다른 디렉토리로 이동하는 명령어

cd는 change directory의 약자로, 다른 디렉토리로 이동하는 명령어이다. cd 현재 로그인한 사용자의 홈 디렉토리로 이동한다. 일반적으로 root 계정이라면 /root로, 사용자 jb 계정이라면 /home/jb로 이동한다. cd ~user user의 홈 디렉토리로 이동한다. 다음과 같이 명령하면 jb 사용자의 홈 디렉토리로 이동한다. # cd ~jb cd 디렉토리명 지정한 디렉토리로 이동한다. 절대경로, 상대경로 다 사용할 수 있다. 다음과 같이 명령하면 /etc 디렉토리로 이동한다. # cd /etc 현재 ...

리눅스 / 스왑 메모리(Swap Memory) 만드는 방법

리눅스 시스템이 메모리를 다 사용하면 프로그램이 멈추는 등 문제가 발생한다. 이때 스왑 메모리(Swap Memory) 늘려서 메모리 부족 문제를 해결할 수 있다. 스왑 파일 만들기 적당한 디렉토리에 적당한 이름의 파일을 적당한 크기로 만든다. 예를 들어 다음과 같이 하면, 루트 디렉토리에 jb-swap이라는 파일을 2G의 크기로 만든다. # fallocate -l 2G /jb-swap root만 읽고 쓸 수 있게 권한 ...

리눅스 / 사용자 / 사용자 조회, 사용자 추가, 사용자 삭제, 사용자 수정

사용자 조회 모든 사용자를 출력합니다. # cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin ... root과 useradd 또는 adduser를 통해 생성한 사용자 계정을 출력합니다. # grep /bin/bash /etc/passwd root:x:0:0:root:/root:/bin/bash jb:x:1000:1000:JB:/home/jb:/bin/bash 사용자 추가 useradd jb 사용자를 만듭니다. useradd jb 사용자 홈 디렉토리도 같이 만들고 싶다면 -d 옵션을 사용합니다. useradd jb -d /home/jbdir jb 사용자의 비밀번호를 만듭니다. passwd jb adduser adduser 명령어로 사용자를 추가할 수 있습니다. useradd와는 달리 사용자 홈 디렉토리를 자동으로 만들고, 비밀번호 ...

리눅스 / 명령어 / passwd / 사용자 암호 설정 명령어

사용자의 비밀번호 설정은 passwd 명령어로 한다. 비밀번호 만들기, 변경하기 사용자 jb의 비밀번호를 만들거나 변경한다. passwd jb 사용자을 적지 않으면 현재 로그인한 사용자의 비밀번호를 만들거나 변경한다. 비밀번호 삭제하기 사용자 jb의 비밀번호를 삭제한다. 사용자는 비밀번호 입력 없이 로그인 가능하다. passwd -d jb 비밀번호 잠그기, 잠금 풀기 사용자 jb를 잠근다. 즉, 사용자는 로그인하지 못한다. passwd -l jb 사용자 jb의 잠금을 푼다. passwd -u jb 비밀번호 만료시키기 사용자 ...