1. 程式人生 > >基於linux下的使用者遠端連線和使用者加密設定

基於linux下的使用者遠端連線和使用者加密設定

這一篇主要講遠端連線和對使用者進行加密設定,確保使用者更安全的被其他使用者進行連線,遠端連線的前提需要設定ip地址,設定過程如下

1.開啟虛擬機器,輸入nm-connection-editor進入設定地址介面

2.選擇ethernet介面,connection name可以使用者自己根據需要選擇選擇與之名字相關的選項,點選ipv4 settings介面,選擇manual,點選add進入設定ip地址,輸入想要設定的ip地址,不能超過255,ip地址後面netmask網路掩碼可以選擇24,,輸入之後點選儲存,ip地址設定成功



一、遠端連線

1.確定開啟網路對外連線的藉口,通過ping -c1 服務端使用者@服務端IP地址 來檢查是否對外可以連線,(ping是檢查是否連通,所以應該在客戶端進行試驗)

2.使用ssh  服務端使用者@服務端ip地址,在客戶端使用ssh命令對客戶端ip地址的客戶端使用者進行連線

示例如下

exit 退出當前連線介面

注意:以上連線方式是不能開啟遠端主機的圖形功能的,如果需要開啟遠端主機圖形功能需要輸入 -X"

ssh -X [email protected]

二、使用者加密

給ssh服務新增新的key認證方式

[[email protected] Desktop]# 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:
6b:88:5a:b3:08:3d:82:ec:95:ae:ea:18:b5:e2:4d:9d

[email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
|  .    S        |
|oo .o... .       |
|*.+++E. o        |
|+=== o .         |
|==+o.            |
+-----------------+

[[email protected] Desktop]# ssh-copy-id -i /root/.ssh/

[email protected] 

【註釋:ssh-copy-id     加密命令
             -i         
指定金鑰
             /root/.ssh/id_rsa.pub  
金鑰
            root           
加密使用者
            172.25.254.109     ##
主機ip】

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filterout any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you areprompted 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 '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[[email protected] Desktop]# scp /root/.ssh/[email protected]:/root/.ssh/

[email protected]'s password:解密檔案傳輸到客戶端

id_rsa                                           100% 1679     1.6KB/s   00:00   

在客戶端進行連線服務端驗證

1.在客戶端
ssh [email protected]    
連線不需要密碼2.在服務端

rm -fr /root/.ssh/authorized_keys   ##當此檔案被刪除,客戶端解密檔案失效

客戶端:

cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys ##從新生成鎖檔案,解密檔案功能恢復

三、sshd的驗證配置

1.輸入 vim /etc/ssh/sshd_config,進入檔案對其安全認證方式及其許可權進行更改

78 PasswordAuthentication no|yes    ##開啟或關閉ssh的預設認證方式

以下三種許可權設定必須在認證方式開啟情況下進行驗證

48 PermitRootLogin no|yes       ##開啟或關閉root使用者的登陸許可權
79 AllowUsers westos            ##
使用者白名單,當前設定是隻允許westos登陸
80 DenyUsers linux          ##
使用者黑名單,當前設定是隻不允許linux登陸

設定完畢,在客戶端轉變使用者進行驗證。

四、linux中服務的管理

systemctl        動作           服務                  

systemctl        start           sshd              開啟服務

systemctl         stop          sshd             停止服務

systemctl         status        sshd              檢視服務狀態

systemctl         restart       sshd               重啟服務

systemctl         reload        sshd              讓服務重新載入配置

systemctl         enable        sshd              設定服務開啟啟動

systemctl         disable        sshd              設定服務開機不啟動

systemctl        list-unit-files                       檢視系統中所有服務的開機啟動狀態

systemctl         list-units                             檢視系統中所有開啟的服務

systemctl          set-default  graphical.target  開機時開啟圖形

systemctl          set-default  multi-user.targe    開機不開啟圖形




相關推薦

no