1. 程式人生 > >Linux----- openssh-server

Linux----- openssh-server

linux---opensshd-server

一、openssh-server

1.功能:讓遠程主機可以通過網絡訪問sshd服務,開始一個安全shell

(1)先創建兩個環境---開啟兩臺虛擬機

(2)一臺作為服務端,將其主機名用一下命令更改(以便區分)

hostnamectl set-hostname ssh-sever.example.com

另一臺作為客戶端,同樣將其主機名進行修改

hostnamectl set-hostname client.example.com

(註:example.com是域名,不予顯示)

註:修改完成後,一定要關掉shell再重新開啟shell修改才生效。

技術分享

nm-connection-editor 配置ip

點擊add

技術分享

單擊creat

技術分享

技術分享

設置完成後點擊save

技術分享

ip配置完成

技術分享

設置完成

技術分享

ip addr show 查看ip

技術分享

服務端同樣

技術分享

技術分享

2.ssh遠程主機用戶@遠程主機ip

ssh遠程主機用戶@遠程主機ip

[root@client ~]ssh [email protected]

The authenticity of host ‘172.25.60.11 (172.25.60.11)‘ can‘t be established.

ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.

Are you sure you want to continue connecting (yes/no)? yes連接陌生主機時需要建立認證關系

Warning: Permanently added ‘172.25.60.11‘ (ECDSA) to the list of known hosts.

[email protected]‘s password: 遠程用戶密碼

Last login: Mon Oct 3 03:13:47 2016

[root@ssh-server ~]登陸成功

技術分享

ssh 遠程主機用戶@遠程主機ip -X 調用遠程主機圖形工具

ssh 遠程主機用戶@遠程主機ipcommand 直接在遠程主機運行某

技術分享

技術分享

產生的進程在服務端

技術分享

在服務端關閉進程客戶端也會關閉

技術分享

服務端進程關閉

技術分享

在服務端建立文件

技術分享

遠程連接進行刪除文件命令

技術分享

刪除圖片成功

技術分享

w -f 查看誰登陸過我

技術分享

技術分享

3.登錄提示字符

vim /etc/motd

技術分享

技術分享

客戶端登錄顯示該字符

技術分享

以上是第一種加密方式

二、sshkey加密

1.生成公鑰私鑰

[root@ssh-server ~]# ssh-keygen 生成公鑰私鑰工具

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):[enter] 加密字符保存文件(建議用默認)

Created directory ‘/root/.ssh‘.

Enter passphrase (empty for no passphrase): [enter] 密鑰密碼,必須>4個字符

Enter same passphrase again: [enter] 確認密碼

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:

ab:3c:73:2e:c8:0b:75:c8:39:3a:46:a2:22:34:84:81 [email protected]

The key‘s randomart image is:

+--[ RSA 2048]----+

|o |

|E.

|.. |

|. . o |

|.o. * . S |

|oo.o o . |

|+ =. . . |

|o. oo.+.. |

| ..o*. |

+-----------------+

[root@server0 ~]# ls /root/.ssh/

id_rsa id_rsa.pub

id_rsa 私鑰,就是鑰匙

id_rsa.pub 公鑰,就是鎖

ssh-keygen 生成公鑰私鑰工具

以下是第二種加密方式

技術分享

ls 列出.ssh 可以看到已生成鎖和鑰匙

2.添加key認證方式

[root@ssh-server ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]

ssh-copy-id 添加key認證方式的工具

-i 指定加密key文件

/root/.ssh/id_rsa.pub 加密key

root 加密用戶為root

172.25.60.11被加密主機ip

技術分享

技術分享

3.提升安全級別

更改配置文件 vim /etc/ssh/ssh_config

將78行 yes改為no,restart該文件,密鑰加密生效

技術分享

技術分享

權利被禁止

技術分享

4.分發鑰匙給client主機

[root@ssh-server ~]# scp /root/.ssh/id_rsa [email protected]:/root/.ssh/

技術分享

分發鑰匙成功

技術分享

登錄成功

5.提升安全級別

(1)更改配置文件 vim/etc/ssh/sshd_config

將78行 yes改為no

技術分享

技術分享

技術分享

技術分享

技術分享

(2)提升安全級別

更改配置 vim /etc/ssh_config

79 Allowusers ww root 允許ww root 用戶登錄

設置白名單

技術分享

技術分享

技術分享

登錄成功

技術分享

(3)提升安全級別

# 註釋掉白名單用戶

80 Denyusers ww 拒絕ww用戶登錄

設置黑名單用戶

技術分享

技術分享

技術分享

ww是黑名單用戶,權利被禁止

技術分享

技術分享

root 用戶權利過大,要禁止它的權利

48 PermitRootLogin yes|no 是否允許超級用戶登陸

更改如下配置文件

技術分享

技術分享

技術分享

root 用戶被禁止,普通用戶可登陸

技術分享

6.控制ssh客戶端訪問

vim /etc/hosts.deny

sshd:ALL 拒絕所有人鏈接sshd服務

vim /etc/hosts.allow

sshd:172.25.254.250 允許250主機鏈接sshd

sshd:172.25.254.250, 172.25.254.180 允許250和180鏈接

sshd:ALL EXCEPT 172.25.254.200 只不允許200鏈接sshd

技術分享

技術分享

技術分享技術分享

技術分享

技術分享



Linux----- openssh-server