Learning/└◆Linux

ssh/scp/sftp CMD 사용법

Gopzero 2016. 12. 29. 19:12



----------------------------------------------------------------------

(이론1) ssh/scp/sftp CMD 사용법

----------------------------------------------------------------------

■ ssh CMD 사용법

# ssh <USER>@<IP> (EX) # ssh 192.168.20.200

# ssh <USER>@<IP> <CMD> (EX) # ssh 192.168.20.200 hostname

 

 

사용시스템

- linux200 (192.168.20.200)

- KaliLinux (192.168.20.50)

 

(KaliLinux)

ssh 192.168.20.200

root 사용자로 로그인

# hostname

# id

# exit

 

# cd ~/.ssh

# cat known_hosts

 

ssh user01@192.168.20.200

user01 사용자로 로그인

$ hostname

$ id

$ exit

#

 

# cd ~/.ssh

# > known_hosts

 

# ssh 192.168.20.200 hostname

yes

root 사용자의 암호 입력

ssh <IP> <CMD> 상대 서버에서 명령어를 실행한 뒤 빠져나온다.

동작은 상대 서버에서 하고 출력만 보내준다.

# ssh user01@192.168.20.200 id

user01 사용자의 암호 입력

# ssh user01@192.168.20.200 "hostname ; id"

user01 사용자의 암호 입력

여러개의 명령어를 동시 수행할 수 있다.

----------------------------------------------------------------

■ scp CMD 사용법

# scp file1 192.168.20.200:/tmp

# scp file1 192.168.20.200:/tmp/file2

# scp 192.168.20.200:/tmp/file2 /test

# scp -r dir1 192.168.20.200:/tmp

scp <file> <IP>:/<경로>

# cd ~/.ssh

# > known_hosts

 

# scp /root/bin/reverse_test.exe 192.168.20.200:/tmp

root 사용자의 암호 입력

# ssh 192.168.20.200 ls -l /tmp/reverse*

root 사용자의 암호 입력

 

# scp 192.168.20.200:/tmp/reverse* /test

root 사용자의 암호 입력

# ls -l /test/reverse*

 

# scp -r /test 192.168.20.200:/tmp

root 사용자의 암호 입력

# ls -l /test

# ssh 192.168.20.200 ls -l /tmp/test

root 사용자의 암호 입력

 

 

------------------------------------------

(이론2) 인증 없이 명령어 수행

------------------------------------------

 

-------- hostA ------ ------- hostB -------

# ssh-keygen CMD

- id_rsa

- id_rsa.pub --------------------> authorized_keys

 

 

(KaliLinux)

# ssh-keygen -t rsa (# ssh-keygen -t dsa)

<ENTER>

<ENTER>

<ENTER>

# cd ~/.ssh

# ls

id_rsa /* private key file */

id_rsa.pub /* public key file */

 

# scp id_rsa.pub 192.168.20.200:/root/.ssh/authorized_keys

root 사용자의 암호 입력

# ssh 192.168.20.200 ls -l /root/.ssh

-> root 사용자 암호 입력 없이 명령어 수행 가능

 

# ssh 192.168.20.200

# hostname

# id

# exit

 

# scp 192.168.20.200:/etc/hosts /test

# cat /test/hosts

 

# cd ~/.ssh

# ls

# mv id_rsa.pub authorized_keys

 

# service ssh restart

# ssh 192.168.20.50 hostname

 

(Debian 계열update-rc.d ssh enable

# service ssh restart

(RedHat 계열) # chkconfig sshd on

# service sshd restart