Linux----- openssh-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