'sftp사용방법'에 해당되는 글 1건

리눅스 sftp 암호입력 없이 사용하는 방법



sftp 뿐만 아니라 rsync, ssh, scp 등 ssh 로그인을 사용하는 유틸은 모두 동일하다.


인증키를 원격지서버에 올리는 방법은 scp 를 설명하는 게시글 https://ivps.tistory.com/77 여기에도 언급되어 있지만 다시 설명하자면 아래와 같다.


ssh-keygen 으로 인증키를 만들어서 원격지 서버로 업로드하면 된다.


▶ ssh 인증키 생성


[root@conoha ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

62:1b:92:d1:58:21:4a:b1:36:86:62:1f:71:90:e0:ec root@conoha.ivps.kr

The key's randomart image is:

+--[ RSA 2048]----+

| .+++.o.         |

|oo +o=           |

|o+*.o .          |

|+o...o           |

| E .o + S        |

|     o +         |

|      .          |

|                 |

|                 |

+-----------------+


[root@conoha ~]# scp -P10022 ./.ssh/id_rsa.pub root@vultr.ivps.kr:~/.ssh/authorized_keys

root@vultr.ivps.kr's password:

id_rsa.pub                                    100%  398     0.4KB/s   00:00


위에서는 scp 로 업로드를 하였지만 sftp 로 올려도 된다.


[root@conoha ~]# sftp -P10022 root@vultr.ivps.kr

root@vultr.ivps.kr's password:

Connected to vultr.ivps.kr.

sftp> put ./.ssh/id_rsa.pub ./.ssh/authorized_keys

Uploading ./.ssh/id_rsa.pub to /root/./.ssh/authorized_keys

./.ssh/id_rsa.pub                             100%  393     0.4KB/s   00:00

sftp> ls .ssh

.ssh/authorized_keys

sftp> bye


위 처럼 /root/.ssh 디렉토리에 authorized_keys 이름으로 인증키를 업로드한 뒤 부터는 비밀번호를 묻지않고 접속이 가능해진다.

 ( 여러개 다수의 서버라면 여기를 참고 https://ivps.tistory.com/79 )



▶ sftp 옵션설명 ( 아래의 옵션은 scp 랑 같다. )


-C 전송시 파일을 압축해서 전송한다.

-l 전송속도 옵션이다. 단위는 Kbit/s

-P 포트지정 옵션이다. 22번 포트는 생략하여도 된다.

-p 원본 파일과 시간을 동일하게 복사한다.

-q 전송진행 상태를 안보여준다.

-r 하위 디렉토리까지 같이 복사하다.

-v 디버깅메시지를 보여준다. 그러나 너무 분잡하다.


그리고 sftp 접속 후의 ls, get, put 등의 명령어는 ftp 명령어랑 똑같다.


[root@conoha ~]# sftp -P10022 -Cpr root@vultr.ivps.kr

Connected to vultr.ivps.kr.

sftp> help

Available commands:

bye                                Quit sftp

cd path                            Change remote directory to 'path'

chgrp grp path                     Change group of file 'path' to 'grp'

chmod mode path                    Change permissions of file 'path' to 'mode'

chown own path                     Change owner of file 'path' to 'own'

df [-hi] [path]                    Display statistics for current directory or

                                   filesystem containing 'path'

exit                               Quit sftp

get [-Ppr] remote [local]          Download file

reget remote [local]            Resume download file

help                               Display this help text

lcd path                           Change local directory to 'path'

lls [ls-options [path]]            Display local directory listing

lmkdir path                        Create local directory

ln [-s] oldpath newpath            Link remote file (-s for symlink)

lpwd                               Print local working directory

ls [-1afhlnrSt] [path]             Display remote directory listing

lumask umask                       Set local umask to 'umask'

mkdir path                         Create remote directory

progress                           Toggle display of progress meter

put [-Ppr] local [remote]          Upload file

pwd                                Display remote working directory

quit                               Quit sftp

rename oldpath newpath             Rename remote file

rm path                            Delete remote file

rmdir path                         Remove remote directory

symlink oldpath newpath            Symlink remote file

version                            Show SFTP version

!command                           Execute 'command' in local shell

!                                  Escape to local shell

?                                  Synonym for help

sftp> !


아래는 배치파일로 업로드 및 다운로드 하는 방법이다.


[root@conoha ~]# dd if=/dev/zero of=./100M.bin bs=100M count=1

1+0 records in

1+0 records out

104857600 bytes (105 MB) copied, 0.169097 s, 620 MB/s

[root@conoha ~]# echo "put 100M.bin" > sftp.batch

[root@conoha ~]# echo "get 100M.bin" >> sftp.batch

[root@conoha ~]# sftp -P10022 -Cpr -b sftp.batch root@vultr.ivps.kr

sftp> put 100M.bin

sftp> get 100M.bin


옵션 -b 패치파일 형태이다.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,