Linux遠程連接——SSH服務,netstat

遠程連接

1、Telnet 端口: 23 明文,不加密,不安全

2、SSH 端口:22 安全 非對稱加密和對稱加密結合


非對稱加密

secret key 私鑰 服務器端

public key 公鑰 客戶端


認證過程

Linux:openssh


c/s架構

服務器端: sshd服務 配置文件/etc/ssh/sshd_config

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


有關ssh服務的命令:

ssh 遠程連接

ssh-keygen 密鑰生成器

ssh-copy-id 將公鑰傳輸至遠程服務器

scp 跨主機拷貝文件


一、基於口令認證

image.png

ssh 10.0.0.31

1、10.0.0.31(nfs01)會給 xwj(客戶端)創建一個存放nfs01公鑰的文件  在客戶端的家目錄下 ~.ssh/known_hosts 文件

image.png

2、然後才能輸入密碼登錄

image.png

3、如果是再次ssh 10.0.0.31,直接輸入密碼登錄即可

image.png


4、指定用戶登錄

ssh username@host

例如

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

[email protected]'s password: 

[zhang@nfs01 ~]$ 

[zhang@nfs01 ~]$ 


二、基於祕鑰認證

image.png


第一步:生成密鑰對


命令1:交互式輸入

[root@xwj ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 

Created directory '/root/.ssh'.

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.


命令2:用參數一步搞定

[root@xwj ~]# ssh-keygen -t rsa -f /root/.ssh/id_rsa  -P ''


用一條命令搞定,有助於將來實現自動化

-f 指定文件名

-P 指定生成密鑰的密碼(爲空)

Generating public/private rsa key pair.

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.


第二步:將~/.ssh/id_rsa.pub文件拷貝到nfs01(10.0.0.31)

方法1、scp拷貝

將~/.ssh/id_rsa.pub文件拷貝到nfs01(10.0.0.31)主機~/.ssh/目錄下 並重命名爲authorized_keys

[root@xwj ~]# scp .ssh/id_rsa.pub  [email protected]:~/.ssh/authorized_keys

權限.ssh爲700

權限authorized_keys爲600

[root@nfs01 ~]# chmod 700 .ssh

[root@nfs01 ~]# chmod 600 ~/.ssh/authorized_keys


方法2、ssh-copy-id命令拷貝

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



補充:netstat 命令

netstat -r 顯示路由信息

 -l 監聽

 -n 以數字方式顯示IP地址和端口號

 -t tcp

 -u udp

 -p 顯示是哪個服務在監聽此端口


netstat -lntup 組合使用

110.png

111.png

netstat -tu 查看建立連接的會話

112.png



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