scp보다 좀 더 기능이 많은 sftp도 있습니다.

sftp도 ssh를 기반으로 실행되며 sftp로 remote server로 접속 후 get 또는 put 명령으로 파일일 내려받거나 올릴 수 있습니다. shell(interactive command) 명령도 사용할 수 있습니다.

 

먼저 sftp로 remote server에 접속합니다.

$ sftp tongchun@10.10.0.118

tongchun@10.10.0.118's password:

Connected to tongchun@10.10.0.118.

sftp>

 

 

 

sftp로 접속하면 sftp 프롬프트 창이 생성됩니다.

sftp 프롬프트 창에서 ls -al, cd, mkdir 등의 interactive command를 실행할 수 있습니다.

사용할 수 있는 interactive command 명령은 아래 링크에서 확인할 수 있습니다.

https://www.mankier.com/1/sftp#Interactive_Commands

 

sftp - secure file transfer program - man page | ManKier

Batch mode reads a series of commands from an input batchfile instead of stdin. Since it lacks user interaction it should be used in conjunction with non-interactive authentication to obviate the need to enter a password at connection time (see sshd(8) and

www.mankier.com

가장 많이 사용하는 명령은 cd, mkdir, pwd, get, put, exit 정도입니다.

sftp로 remote server 접속 후 cd로 파일을 내려받거나 올리고자 하는 경로로 이동합니다.

그리고 get으로 파일을 다운 받거나, put으로 파일을 올릴 수 있습니다.

sftp 프롬프트 창을 종료하려면 exit 명령을 실행하면 됩니다.

 

위에서 접속한 10.10.0.118 서버에서 pwd 명령으로 디렉토리 경로를 확인해 봅니다.

sftp> pwd

Remote working directory: /home/tongchun

 

 

pwd 명령을 실행하면 remote server의 디렉토리 경로를 확인할 수 있습니다.

lpwd 명령을 실행하면 현재의 로컬 PC의 경로를 확인할 수 있습니다.

sftp> lpwd

Local working directory: /Users/tongchunkim

 

 

이번엔 파일 리스트를 확인해 봅니다.

sftp> ls -l

drwxrwxr-x 5 tongchun tongchun 39 Apr 17 05:59 go

-rw-rw-r-- 1 tongchun tongchun 127928770 Apr 11 22:09 go1.12.4.linux-amd64.tar.gz

-rw-r--r-- 1 root root 6140 Nov 12 2015 mysql-community-release-el7-5.noarch.rpm

 

 

 

go1.12.4.linux-amd64.tar.gz 파일을 다운받아 보겠습니다. 명령어는 get 입니다.

sftp> get go1.12.4.linux-amd64.tar.gz

Fetching /home/tongchun/go1.12.4.linux-amd64.tar.gz to go1.12.4.linux-amd64.tar.gz

/home/tongchun/go1.12.4.linux-amd64.tar.gz 100% 122MB 57.0MB/s 00:02

 

 

 

잘 받아졌는지 로컬 PC의 파일 리스트를 확인해 봅니다. 로컬 PC에 명령을 보내려면 remote server에서 사용한 명령 앞에 l를 붙여줍니다.

sftp> lls -l

total 263904

drwxr-xr-x 3 tongchunkim staff 96 7 30 2018 AndroidStudioProjects

drwx------@ 4 tongchunkim staff 128 12 12 2017 Applications

drwx------+ 6 tongchunkim staff 192 4 22 19:08 Desktop

drwx------+ 31 tongchunkim staff 992 3 18 10:00 Documents

drwx------+ 75 tongchunkim staff 2400 4 25 16:54 Downloads

drwx------@ 10 tongchunkim staff 320 1 28 19:18 Dropbox

drwx------@ 83 tongchunkim staff 2656 4 6 14:16 Library

drwx------+ 3 tongchunkim staff 96 12 12 2017 Movies

-rw-r--r-- 1 tongchunkim staff 127928770 4 26 14:44 go1.12.4.linux-amd64.tar.gz

-rw-r--r-- 1 tongchunkim staff 9180 1 12 2018 jmeter.log

drwxr-xr-x 14 tongchunkim staff 448 2 6 2018 macaronRamlProject

-rw-r--r-- 1 tongchunkim staff 26484 7 29 2018 package-lock.json

drwxr-xr-x 3 tongchunkim staff 96 9 16 2018 snakepit

 

 

go1.12.4.linux-amd64.tar.gz이 보이네요.

 

이번에는 파일을 업로드해 보겠습니다. jmeter.log 파일을 올려봅시다. 파일을 올리는 명령은 put입니다.

sftp> put jmeter.log

Uploading jmeter.log to /home/tongchun/jmeter.log

jmeter.log 100% 9180 268.9KB/s 00:00

 

 

 

파일이 잘 올라갔는지 확인해 봅니다.

sftp> ls -l

drwxrwxr-x 5 tongchun tongchun 39 Apr 17 05:59 go

-rw-rw-r-- 1 tongchun tongchun 127928770 Apr 11 22:09 go1.12.4.linux-amd64.tar.gz

-rw-r--r-- 1 tongchun tongchun 9180 Apr 26 01:49 jmeter.log

-rw-r--r-- 1 root root 6140 Nov 12 2015 mysql-community-release-el7-5.noarch.rpm

 

 

 

파일이 잘 올라가네요.

sftp를 종료할 때는 exit 입니다.

다른 interactive command를 확인하면 더 유용하게 사용할 수 있을 것 같습니다.

'program > linux-common' 카테고리의 다른 글

rcp remote 상에서의 파일 전송  (0) 2021.07.06
rlogin  (0) 2021.05.12
리눅스 환경 변수 설정  (0) 2021.03.27
linux 패키지 관리 프로그램 snap apt  (0) 2021.03.26
ubuntu 에서 github-desktop 설치하기  (0) 2021.03.26

2. 원격접속과 파일전송
    ■ 원격 접속 명령어 : telnet, rlogin, rsh, ssh
    ■ 파일 전송 명령어 : ftp, rcp, scp, sftp

    ■ 암호화를 하지 않는 명령어: telnet, ftp, rlogin, rsh, rcp
    ■ 암호화를 하는 명령어 : ssh, scp, sftp

3. 원격접속 & 파일전송 명령어(System V 계열)
    가. telnet
        1) telnet 명령어 실행 모드
            ▪ 대화형 모드 (Interractive Mode)
                # telnet
                telnet>
            ▪ 비대화형 모드(Noninterractive Mode)
                # telnet solaris254
                # telnet 172.16.8.254
        2) 기본 사용법
            # telnet 172.16.8.254
               # telnet 172.16.8.254 23    (/etc/services 정의)
            # telnet solaris254            (/etc/hosts 정의, /etc/inet/ipnodes 정의)
                                    /etc/inet/hosts <--- /etc/hosts
                                    /etc/inet/hosts <--- /etc/inet/ipnodes
            ---------------------------------------
            포트 서비스명
            ---------------------------------------
            20,21    FTP
            22        SSH
            23        TELNET
            25        SMTP
            53        DNS
            67,68    DHCP(Bootp)
            80        WEB
            110        POP3
            111        sunrpc
            123        NTP
            143        IMAP
            ---------------------------------------
        3) telnet 연결 화면시 에러 메세지
            가) 상대편 서버의 이름을 잘못 지정한 경우
                메시지 : Unknown host
            나) 서버가 정상적으로 동작하지 않는 경우
                메시지 : Connection refused
                메시지 : Connection timed out
                - ping 명령으로 확인
            다) 로그인시 암호가 틀린 경우
                메시지 : Login incorrect
            라) root 사용자로 로그인시 CONSOLE 변수가 잘못 지정된 경우
                메시지 : Not on system console
                - Solaris 기본 설정으로 /etc/default/login 파일을 열어서 CONSOLE변수 부분을 #으로 주석처리
            마) TCP_Wrapper에 의해 막힌 경우
                메시지 : Connection to solaris254 closed by foreign host.
    가. ftp
        1) ftp 명령어 실습1
            가) 업로드/다운로드 포인터맞추기(upload/download pointer)
                [참고] 업로드/다운로드 포인터
                ===== HOSTA ===== ===== HOSTB =====
                현재 디렉토리 ----------------> 홈디렉토리
                (예) /test /
                upload /tmp/test.solarisXXX ---> /test
                download /root <------------------ /test/test.solarisXXX
            나) 편리한 기능 설정(FTP function)
                ftp> bin (ftp> binary)    binary모드로 전송
                ftp> ascii                ascii 모드로 전송
                ftp> hash                8K마다 #표시
                ftp> prompt            대화형모드설정(토글)
            다) 업로드/다운로드(upload/download)
                ftp> put test.solarisXXX        한개의 파일 업로드
                ftp> get test.solarisXXX    한개의 파일 다운로드
                ftp> mput test.*            여러개의 파일 업로드
                ftp> mget test.*            여러개의 파일 다운로드
            라). 확인 및 접속 종료
                ftp> ls [-al]                파일 확인(서버쪽)
                ftp> dir [-al]                파일 확인(서버쪽)
                [참고] ftp> ! ls                파일 확인(자기자신)
            [참고] 자동 파일 업/다운로드 스크립트
                # rcp 172.16.8.254:/root/shell/suto_ftp.sh /test
                # cat /test/auto_ftp.sh
                내용
                ------------------------------------------------------
                #! bin/ksh
                ftp -n 172.16.8.254 21 << EOF
                user user01 user01            /* user <사용 ID> <사용P/W> */
                bin                            /* 편리한 기능 설정*/
                hash
                prompt
                cd download                    /* 업로드/다운로드 포인터 맞추기 */
                lcd /test
                put test.solarisXXX            /* 파일 전송 */
                bye
                EOF
                ------------------------------------------------------
        3) ftp 명령어 실습 2
        4) ftp 관련 파일들
            가) /etc/ftpd/ftpusers FTP 접속 불가 사용자 정의
                (FTP 서버 사용자 기본 정책)
                - root 사용자는 FTP 서버에 접속 불가능
                - 일반 사용자는 접속 가능(예: user01, user02....)
            나) /etc/shells FTP 접속시 할당할 수 있는 쉘 정의
                - ftp 접속시 해당유저에 할당되어 있는(/etc/passwd파일의 끝) 쉘을 기본으로 할당
                - /etc/shells가 있으면 파일 안에 있는 설정의 쉘을 할당 받는다.
                    -> 해당 쉘을 사용하는 사용자만 FTP 서버에 로그인이 가능하다
            [EX] 실무적인 예(/etc/shells)
            사용자 (예: user01, user02 ...., test01, test02, ...., solaris01, solaris02,...)
                        /bin/ksh            /bin/csh            /bin/bash
                - 호스트별 FTP 접근 제어 : /etc/ftpd/ftphosts, TCP_Wrapper, Firewall(IPFilter), ...
                - 사용자별 FTP 접근 제어 : /etc/ftpd/ftpusers
                - 쉘별 FTP 접근 제어 : /etc/shells
4. 원격접속 & 파일전송 명령어(BSD계열)
Remote Connection & File Transmission for BSD
■ rlogin 명령어    Remote Login CMD
■ rsh 명령어        Remote Shell CMD
■ rcp 명령어        Remote Copy CMD
    가. r 명령어(CMD) 동작원리
    Remote Connection & File Transmission for BSD
    HOSTA ----------> HOSTB
    # telnet B        Auth(ID/PASS)
    # rlogin B        Auth(/etc/hosts.equiv, ~/.rhosts)
    /etc/hosts.equiv System wild Conf.
    ~/.rhosts System specific Conf.
        ____________________
        (호스트이름) (사용자이름)
        HOSTA
        HOSTA        user01
            +
        HOSTA -------> HOSTB
                    /etc/hosts.equiv (All users, root 사용자 인증 제외)
                    ---------------------
                    HOSTA                HOSTA의 모든 사용자 인증(단, 이름이 같은 사용자)
                    HOSTA         +        HOSTA의 모든 사용자 인증
                    HOSTA        user01    HOSTA의 user01 사용자만 인증
                    +            user01    모든 호스트의 user01 사용자 인증
                    +             +        모든 호스트의 모든 사용자 인증
        HOSTA -------> HOSTB
                    ~user01/.rhosts (user01)
                    ---------------------
                    HOSTA                HOSTA의 모든 사용자 인증(단, 이름이 같은 사용자)
                    HOSTA        +        HOSTA의 모든 사용자 인증
                    HOSTA        user01    HOSTA의 user01 사용자만 인증
                    +            user01    모든 호스트의 user01 사용자 인증
                    +            +        모든 호스트의 모든 사용자 인증
    나. rlogin
        - 명령어 사용법
            # rlogin hostname
            # rlogin -l username hostname (-l : login name)
            # rlogin username@hostname
    다. rsh
        # rsh hostname CMD
        # rsh 172.16.8.254 hostname
        # rsh 172.16.8.254 ls -l /tmp
        # rsh 172.16.8.254 ls -l /root/docs
    라. rcp
        # rcp file1 172.16.8.254:/tmp
        # rcp 172.16.8.254:/tmp/file1 /tmp
        # rcp -r dir1 172.16.8.254:/tmp
        # rcp -r 172.16.8.254:/root/shell /root
        # rcp -r 172.16.8.254:/root/* .
        # rcp file1 user01@172.16.8.254:/tmp
    [참고] .rhosts 파일 정책(Policy)
        (a). 사용자 홈디렉토리에 .rhosts 파일을 정기적으로 지우는정책
            # find /export/home -name .rhosts -type f -exec rm {} \;
        (b). 사용자 홈디렉토리에 .rhosts 파일을 못 만들도록 하는 정책
            user01 Home Directory : /export/home/user01
            # cd /export/home/user01
            # mkdir .rhosts (rwxr-xr-x root other)
            # touch .rhosts/.notperm (rw-r--r-- root other)
            # chmod 000 .rhosts
            # chmod 000 .rhosts/.notperm
5. 원격접속 & 파일전송 명령어(암호화 방식)
    Remote Connection & File Transmission for Securiy
        ■ ssh 명령어 Secure Shell
        ■ scp 명령어 Secure Copy
        ■ sftp 명령어 Secure FTP
    가. ssh
        - rsh를 기반으로 만들어져 사용법이 비슷하다.
        # ssh hostname
        # ssh -l username hostname
        # ssh username@hostname
    나. sftp
        - ftp 명령어를 기반으로 만들어져 사용법이 비슷하다.
        # sftp 172.16.8.254
        # sftp user01@solaris254
    다. scp
        - rcp 명령어를 기반으로 만들어져 사용법이 비슷하다.
        # scp /tmp/file1 172.16.8.254:/tmp
        # scp -r /root/test 172.16.8.254:/tmp
        # scp -r 172.16.8.254:/tmp/* /test
        # scp -r file1 user01@172.16.8.254:/tmp

+ Recent posts