linux 中SSH 服務

SSH 遠程管理服務

1.ssh簡介

ssh爲Secure Shell 的縮寫。SSH 爲建立在應用層和傳輸層基礎上的安全協議
端口號 :22
linux 中守護進程 :sshd
安全服務:OpenSSH
服務端主程序 :/usr/sbin/sshd
客戶端主程序 :/usr/bin/ssh

服務端配置文件 : /etc/ssh/sshd_config
客戶端配置文件 :/etc/ssh/ssh_config

ssh 服務是linux 默認安裝

2.SSH 加密原理

對稱加密 :用同一個密碼可以 加密和解密
非對稱加密:需要用兩個密鑰進行加密和解密 稱爲公鑰和私鑰。

ssh採用 非對稱加密

ssh加密保護文件非安全 不被竊取

3.SSH的配置文件

Port 22 端口
Listenaddress 監聽的ip
Protol 2 ssh版本
hostKey 私鑰保存位置
ServerKeyBits 1024 私鑰的位數

4.SSH 命令
ssh root@要管理的linux主機ip
exit 退出

[root@localhost ~]# ssh  [email protected]
[email protected]'s password:
Last login: Mon Sep 24 21:57:47 2018 from 192.168.144.11

scp 遠程複製
下載
scp [email protected]:/root/text.txt .

下載其他主機文件 到當前目錄
[root@localhost ~]# scp [email protected]:/tmp/1  .
[email protected]'s password:
1                                                                                                          100%    0     0.0KB/s   00:00

上傳
scp -r /root/123/ [email protected]/root

將本機tmp目錄 上傳至別的主機tmp下
[root@localhost ~]# scp -r /tmp/  [email protected]:/tmp
[email protected]'s password:

輸入密碼即可

ssh 的密鑰和登錄 就是不用密碼驗證
簡稱免密鑰登錄

步驟爲將客戶端的公鑰導入服務器端的指定文件中,則客戶端可以使用私鑰接入和管理服務器端
本次實驗 客戶端ip 爲 192.168.125.129
服務端 ip 爲 192.168.125.128

步驟一 :
1.在本地主機生成 “密鑰對” 並將公鑰傳送到遠程主機中

[root@localhost ~]# ssh-keygen
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:
fc:1d:b0:94:b7:4c:81:c2:b6:5d:7e:8c:13:b9:17:b4 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|       .   ..o.  |
|        + ..+... |
|       . ++oo=E. |
|       ....*=.+  |
|        S . ++   |
|         . . .   |
|          . .    |
|                 |
|                 |
+-----------------+

將生成好的公鑰密鑰傳送到遠程主機



[root@localhost ~]# ssh-copy-id  192.168.125.128
The authenticity of host '192.168.125.128 (192.168.125.128)' can't be established.
ECDSA key fingerprint is 9e:3a:84:61:9f:5c:a7:95:1b:69:27:5b:51:ca:6f:21.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.125.128'"
and check to make sure that only the key(s) you wanted were added.


第二步 :在遠程主機中修改sshd服務的配置文件 (修改後要重啓服務)

1.編輯ssh服務程序主配置文件

注意 : 是在遠程主機端修改ssh主配置文件
[root@localhost ~]# vi /etc/ssh/sshd_config

將允許密碼驗證的參數設置爲no
在這裏插入圖片描述

3.將允許密鑰驗證的參數設置爲yes
在這裏插入圖片描述
4.保存退出配置文件

5.重啓ssh服務程序即可生效

[root@localhost ~]# ssh 192.168.125.128
Last login: Sun Oct  7 23:16:39 2018 from 192.168.125.129


      *                   *       *         *
      *                     *     *         *
    ******  *****             ********      *
      *  *  *   *        ***  *   *  *      *
     *   *  *****             ********      *
    *  * *                    *   *  *
   *     *               ***  ********      *

成功了 哈哈哈哈!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章