상세 컨텐츠

본문 제목

ssh 를 이용한 network file copy 명령어 (scp 명령어 사용법)

IT : Ubuntu

by 휀스 2014. 10. 6. 01:11

본문



ssh 를 이용한 network file copy 명령어 (scp 명령어 사용법)


Ubunut (Linux) 는 아직까지 UI 가 MS 제품들 보다 사용하기 편하지는 않습니다. 많은 기능들이 command line 에서 이루어 져야하며 text 로 많은 부분의 설정을 건들어야 하는 등 불편한 부분이 많습니다. 그 중 하나가 오늘 주제인 네트웍 파일 복사 명령 scp 입니다. 이 scp 명령은 network drive 나 Samba 로 묶여있지 않은 PC에 로컬의 파일을 전송하거나 복사 할 수 있는 명령입니다.



scp 를 사용하는 방법을 알아 보겠습니다.


scp [[user@]from-host:]source-file [[user@]to-host:][destination-file]


scp 사용자id@전송할컴터:전송할파일 서버사용자id@서버ip:복사할dir과file이름


이렇게 명령어를 사용하여 파일을 전송할 수 있습니다.

[] 안에 있는 내용은 필요하지 않다면 생략이 가능합니다.


실제 사용 예를 들어보면 아래와 같습니다. 현재 디렉토리의 Makefile 을 192.168.68.10 PC 의 /home/hanson/ 폴더로 복사하는 명령입니다.


$ scp Makefile jason@192.168.68.10:/home/banson/

banson@192.168.68.10's password: 

Makefile                                                                                          100%   87     0.1KB/s   00:00



scp 는 여러가지 옵션으로 사용 가능하기 때문에 shell command 를 주로 사용하는 사람이라면 더욱 편하게 사용할 수 있습니다.


-p : 수정시간 access time permission 을 유지

-q : Progress bar 표시 안함

-r : 하위 directory 포함
-v : Debug message 표시


scp 를 보다 잘 사용하려면 rsync 와 같은 명령어를 사용하는 것도 좋습니다.
rsync 는 network file copy일 경우 내부적으로 scp 를 사용한다고 합니다. 게다가 특정 파일을 제외하고 복사하고 용량이 큰 파일의 경우 변경된 부분만 복사하는 등 여러가지 방법이 있으니 잘 알아보고 자신에게 맞는 명령을 선택하여 사용하면 linux ubuntu가 더욱 훌륭한 OS라는 것을 알 수 있을 것 입니다.

이상 ssh 를 이용한 network file copy 명령어 (scp 명령어 사용법)에 대한 글 이였습니다.

참고로 ssh 의 옵션들 입니다.

NAME
     scp -- secure copy (remote file copy program)

SYNOPSIS
     scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ...
         [[user@]host2:]file2

DESCRIPTION
     scp copies files between hosts on a network.  It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as ssh(1).
     Unlike rcp(1), scp will ask for passwords or passphrases if they are needed for authentication.

     File names may contain a user and host specification to indicate that the file is to be copied to/from that host.  Local file names can be made explicit
     using absolute or relative pathnames to avoid scp treating file names containing ':' as host specifiers.  Copies between two remote hosts are also permitted.

     The options are as follows:

     -1      Forces scp to use protocol 1.
     -2      Forces scp to use protocol 2.
     -3      Copies between two remote hosts are transferred through the local host.  Without this option the data is copied directly between the two remote
             hosts.  Note that this option disables the progress meter.
     -4      Forces scp to use IPv4 addresses only.
     -6      Forces scp to use IPv6 addresses only.
     -B      Selects batch mode (prevents asking for passwords or passphrases).
     -C      Compression enable.  Passes the -C flag to ssh(1) to enable compression.
     -c cipher
             Selects the cipher to use for encrypting the data transfer.  This option is directly passed to ssh(1).
     -F ssh_config
             Specifies an alternative per-user configuration file for ssh.  This option is directly passed to ssh(1).
     -i identity_file
             Selects the file from which the identity (private key) for public key authentication is read.  This option is directly passed to ssh(1).
     -l limit
             Limits the used bandwidth, specified in Kbit/s.



관련글 더보기