1. 程式人生 > >Linux的SSH(Secure Shell Protocol)服務

Linux的SSH(Secure Shell Protocol)服務

for authent 緊急 gpo 般的 body 方式 names ask

  在數據傳輸前,SSH會對需要傳輸的數據進行加密,保證會話安全與會話中傳輸數據的安全,SSH客戶端還包含一個遠程拷貝scp。

1、SSH的結構

SSH服務由服務端軟件(openssh)和客戶端(SSH、SecureCRT、Xshell)組成,SSH默認使用22端口,SSH服務端是一個守護進程,在後臺時刻監聽客戶端的請求,sshd就是SSH服務端的進程名

補充:(守護進程)

守護進程是一個在後臺運行並且不受任何終端控制的進程。Unix操作系統有很多典型的守護進程(其數目根據需要或20—50不等),它們在後臺運行,執行不同的管理任務。
用戶使守護進程獨立於所有終端是因為,在守護進程從一個終端啟動的情況下,這同一個終端可能被其他的用戶使用。例如,用戶從一個終端啟動守護進程後退出,然後另外一個人也登錄到這個終端。用戶不希望後者在使用該終端的過程中,接收到守護進程的任何錯誤信息。同樣,由終端鍵人的任何信號(例如中斷信號)也不應該影響先前在該終端啟動的任何守護進程的運行。雖然讓服務器後臺運行很容易(只要shell命令行以
&結尾即可),但用戶還應該做些工作,讓程序本身能夠自動進入後臺,且不依賴於任何終端。 守護進程沒有控制終端,因此當某些情況發生時,不管是一般的報告性信息,還是需由管理員處理的緊急信息,都需要以某種方式輸出。Syslog 函數就是輸出這些信息的標準方法,它把信息發送給 syslogd 守護進程。

2、SSH認證類型

(1)基於口令的安全驗證,也就是通常所說的賬號、密碼、端口、IP登錄

(2)基於密鑰的安全驗證

  事先建立一對密鑰對,然後將公用的密鑰放在服務端,把私有的密鑰放在SSH的客戶端,最終通過這種密鑰驗證方式進行加密傳輸數據。

技術分享圖片

3、SCP

NAME
     scp - secure copy (remote file
copy program)  #安全拷貝 SYNOPSIS scp [-1246BCpqrv] [-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.(scp是在網絡上通過host之間拷貝文件) 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 pass- words 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 speci- fiers. Copies between two remote hosts are also permitted. When copying a source file to a target file which already exists, scp will replace the contents of the target file (keeping the inode). If the target file does not yet exist, an empty file with the target file name is created, then filled with the source file contents. No attempt is made at "near-atomic" transfer using temporary files.

-P  端口

-p  保持屬性

-r  拷貝目錄

技術分享圖片

技術分享圖片

4、FTP功能服務sftp

上傳:

[root@localhost tmp]# sftp -oport=22 root@192.168.181.129
Connecting to 192.168.181.129...
root@192.168.181.129s password: 
sftp> put /tmp/666 /tmp
stat /tmp/666: No such file or directory
sftp> put /tmp/123.txt /tmp
Uploading /tmp/123.txt to /tmp/123.txt
/tmp/123.txt                                100%    0     0.0KB/s   00:00    

技術分享圖片

查看上傳成功!

下載:

sftp> get /tmp/666 /tmp
Fetching /tmp/666 to /tmp/666
sftp> get /tmp/666 /opt
Fetching /tmp/666 to /opt/666

技術分享圖片

檢查下載到本地成功!

Linux的SSH(Secure Shell Protocol)服務