linux中ssh服務

9.openssh-server

1.openssh-server

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

2.客戶端連接方式

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

[root@desktop0 ~]# ssh [email protected]

The authenticity of host '172.25.0.11 (172.25.0.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.0.11' (ECDSA) to the list of known hosts.

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

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

[root@server0 ~]#                ##登陸成功

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

ssh     遠程主機用戶@遠程主機ipcommand                ##直接在遠程主機運行某條命令

3.sshkey加密

1.生成公鑰私鑰

[root@server0 ~]# 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                        ##公鑰,就是鎖

2.添加key認證方式

[root@server0 ~]# 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.55.11                ##被加密主機ip

3.分發鑰匙給client主機

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

4.測試

[root@desktop0 ~]# ssh [email protected] ##通過id_rsa直接連接不需要輸入用戶密碼

Last login: Mon Oct  3 03:58:10 2016 from 172.25.55.11

[root@server0 ~]#

4.提升openssh的安全級別

1.openssh-server配置文件

/etc/ssh/sshd_config

78 PasswordAuthentication yes|no##是否開啓用戶密碼認證,yes爲支持no爲關閉

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

49 AllowUsers student westos##用戶白名單,只有在名單中出現的用戶可以使用sshd建立shell

50 DenyUsers westos##用戶黑名單

2.控制ssh客戶端訪問

vim /etc/hosts.deny

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

vim /etc/hosts.allow

sshd:172.25.55.10                ##允許10主機鏈接sshd

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

sshd:ALL EXCEPT 172.25.55.10##只不允許10鏈接sshd

3.ssh登陸提示修改

vim /etc/motd               ##顯示登陸後字符

hello zzf               ##在登陸後就會顯示這個字符

 

 

發佈了31 篇原創文章 · 獲贊 0 · 訪問量 7624
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章