SSH遠程連接工具原理:ssh服務是一個守護進程(demon),系統后台監聽客戶端的連接,ssh服務端的進程名sshd,負責實時監聽客戶端的請求(ip,22端口),包括公共密鑰等信息。
ssh服務端由兩部分組成:openssh(提供ssh服務),openssl(提供加密服務)
一、SSH的工作機制
服務器啟動時自己產生一個密鑰(768bit的公鑰),本地的ssh客戶端發送連接請求到ssh服務器,服務檢查客戶端發送的請求信息,確認合法后,發送密鑰給客戶端,此時客戶端將本地私鑰(256bit)和服務器的公鑰(768bit)結合成密鑰對key(1024bit),發回給服務器端,建立連接通過key-pair數據傳輸。
二、ssh的加密技術
1.SSH1沒有對客戶端的秘鑰進行校驗,很容易被植入惡意代碼
2.SSH2增加了一個確認聯機正確性的Diffe_Hellman機制,每次數據的傳輸,Server都會檢查數據來源的正確性,避免黑客入侵。
SSH2支持RSA和DSA密鑰
DSA:digital signature Algorithm 數字簽名
RSA:既可以數字簽名又可以加密
三、ssh小知識
1.SSH是安全的加密協議,用於遠程連接Linux服務器
2.SSH的默認端口是22,安全協議版本是SSH2
3.SSH服務器端主要包含2個服務功能SSH連接和SFTP服務器
4.SSH客戶端包含ssh連接命令和遠程拷貝scp命令等
四、后台ssh服務的相關
# 查詢openssl的相關軟件
[root@localhost ~]# rpm -qa openssh openssl
openssl-1.1.1-8.el8.x86_64
openssh-7.8p1-4.el8.x86_64
# 查看sshd進程
[root@localhost ~]# ps -ef |grep ssh
root 1042 1 0 18:20 ? 00:00:00 /usr/sbin/sshd -D -oCiphers=aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes256-cbc,aes128-gcm@openssh.com,aes128-ctr,aes128-cbc -oMACs=hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha1,umac-128@openssh.com,hmac-sha2-512 -oGSSAPIKexAlgorithms=gss-gex-sha1-,gss-group14-sha1- -oKexAlgorithms=curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1 -oHostKeyAlgorithms=rsa-sha2-256,ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,rsa-sha2-512,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,ssh-rsa,ssh-rsa-cert-v01@openssh.com -oPubkeyAcceptedKeyTypes=rsa-sha2-256,ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,rsa-sha2-512,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,ssh-rsa,ssh-rsa-cert-v01@openssh.com
root 1865 1042 0 18:20 ? 00:00:00 sshd: root [priv]
root 2373 1865 0 18:21 ? 00:00:00 sshd: root@pts/0
root 2376 1042 0 18:21 ? 00:00:00 sshd: root [priv]
root 2395 2376 0 18:21 ? 00:00:00 sshd: root@notty
root 2414 2395 0 18:21 ? 00:00:00 /usr/libexec/openssh/sftp-server
root 4661 2378 0 22:35 pts/0 00:00:00 grep --color=auto ssh
# 查看ssh端口
[root@localhost ~]# ss |grep ssh
[root@localhost ~]# netstat -a |grep ssh
[root@localhost ~]# netstat -lnt |grep 22
# 查看ssh的密鑰目錄
[root@localhost ~]# ll /root/.ssh/known_hosts
-rw-r--r--. 1 root root 347 May 7 22:24 /root/.ssh/known_hosts
# ssh的配置文件
/etc/ssh/ssh_config