ssh服務器的架構
-
1.安裝ssh服務器
sudo apt-get install openssh-server
查看ssh服務器是否安裝成功:
ssh -V
-
2.查看ssh組態檔:vim /etc/ssh/sshd_config
用vim進行編輯:
設定成如下:
# Authentication:
LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes
# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no
其中,主要是:
PermitEmptyPasswords no
PermitRootLogin prohibit-password
使得無密碼通過或者是按照服務器的密碼登錄
-
用ssh客戶端登錄:
ssh 本機ip/hostname
- 以超級管理員身份登錄:
ssh root@hostname
當第一次登陸某服務器時:
會出現這些代碼:
The authenticity of host 'foo.com (192.168.121.111)' can't be established.
ECDSA key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY.
Are you sure you want to continue connecting (yes/no)?
這時候出現的這個是我們所謂的密鑰,同時,不同的演算法對應不同的密碼與密鑰(密碼學拓展)
那么這里如果光輸入"yes" 然后再進行進一步的操作——也就是輸入你的服務器密碼時,是不會接通的,
我們將出現過的這個東西:
ECDSA key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY.
- 稱為指紋
類比于指紋,這是一個新的指紋,如何讓它能夠解鎖:
那當然是將它加入到你的指紋中啦,也就是給予它信任:
$ ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub
256 da:24:43:0b:2e:c1:3f:a1:84:13:92:01:52:b4:84:ff (ECDSA)
上面的例子中,ssh-keygen -l -f命令會輸出公鑰/etc/ssh/ssh_host_ecdsa_key.pub的指紋,
ssh 會將本機連接過的所有服務器公鑰的指紋,都儲存在本機的~/.ssh/known_hosts檔案中,每次連接服務器時,通過該檔案判斷是否為陌生主機(陌生公鑰),
在上面這段文字后面,輸入yes,就可以將當前服務器的指紋也儲存在本機~/.ssh/known_hosts檔案中,并顯示下面的提示,以后再連接的時候,就不會再出現警告了,
Warning: Permanently added 'foo.com (192.168.121.111)' (RSA) to the list of known hosts
可能會出現的問題:
ssh: connect to host 192.168.241.128 port 22: Connection refused
-
解決方法:是因為沒有打開ssh服務:
我們用這個命令查看:
service ssh status
得到的結果:
ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:sshd(8)
man:sshd_config(5)
- 我們發現這一行:
Active: inactive (dead) #狀態:inactive
那么也就是我們需要激活ssh服務
service ssh start
啟用ssh服務后:再一次運行
service ssh status
這次得到的結果:
ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2020-12-24 06:58:16 EST; 2s ago
Docs: man:sshd(8)
man:sshd_config(5)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/245176.html
標籤:其他
