溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何進(jìn)行遠(yuǎn)程連接與openssh

發(fā)布時(shí)間:2021-11-08 10:00:12 來源:億速云 閱讀:167 作者:柒染 欄目:建站服務(wù)器

這篇文章將為大家詳細(xì)講解有關(guān)如何進(jìn)行遠(yuǎn)程連接與openssh,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

1、openssh簡(jiǎn)介

  傳統(tǒng)的網(wǎng)絡(luò)程序都是采用明文傳輸數(shù)據(jù)和密碼,如telnet、ftp等,存在很大的安全漏洞,***只需要使用一些數(shù)據(jù)包截取工具就可以獲得包括密碼在內(nèi)的重要數(shù)據(jù)。正因如此,后來才出現(xiàn)了SSH (Secure shell,安全命令殼)。SSH是由芬蘭的一家公司所研發(fā)的加密通信協(xié)議,所有SSH傳輸?shù)臄?shù)據(jù)都是經(jīng)過加密,可以有效防止數(shù)據(jù)的竊取以及'中間人'的***。SSH建立在應(yīng)用層和傳輸層基礎(chǔ)上的安全協(xié)議,監(jiān)聽tcp的22號(hào)端口,屬于是文本協(xié)議。OpenSSH是SSH的替代軟件,完全免費(fèi)并且開放源代碼。當(dāng)前ssh協(xié)議版本主要有兩種:

  sshv1是基于CRC-32做MAC,因此,不安全,建議勿用;

  sshv2基于雙方主機(jī)協(xié)商選擇最安全的MAC實(shí)現(xiàn)機(jī)制;加密機(jī)制及MAC機(jī)制是雙方協(xié)商選定;基于DH實(shí)現(xiàn)密鑰交換,基于RSA或DSA實(shí)現(xiàn)身份認(rèn)證;客戶通過檢查服務(wù)端的主機(jī)密鑰來判定是否與其進(jìn)一步通信。

  基于sshv2版本的通信方式主要如下圖所示;

如何進(jìn)行遠(yuǎn)程連接與openssh

  在Centos6中已經(jīng)默認(rèn)安裝了openssh,可以使用如下命令查看安裝情況:

[root@mylinux ~]# rpm -qa |grep ssh
openssh-clients-5.3p1-118.1.el6_8.x86_64     #openssh的客戶端程序
libssh3-1.4.2-2.el6_7.1.x86_64               #openssh的協(xié)議實(shí)現(xiàn)模塊
openssh-5.3p1-118.1.el6_8.x86_64             #openssh的主程序文件
openssh-server-5.3p1-118.1.el6_8.x86_64      #openssh的服務(wù)器程序

  安裝openssh后,會(huì)在系統(tǒng)中創(chuàng)建名為sshd的服務(wù),用戶可以通過該服務(wù)啟動(dòng)或關(guān)閉openssh。默認(rèn)情況下,openssh會(huì)開機(jī)自動(dòng)啟動(dòng)。

[root@mylinux ~]# chkconfig --list sshd     
sshd            0:關(guān)閉  1:關(guān)閉  2:啟用  3:啟用  4:啟用  5:啟用  6:關(guān)閉
[root@mylinux ~]# chkconfig --level 2345 sshd off
[root@mylinux ~]# chkconfig --list sshd          
sshd            0:關(guān)閉  1:關(guān)閉  2:關(guān)閉  3:關(guān)閉  4:關(guān)閉  5:關(guān)閉  6:關(guān)閉
[root@mylinux ~]# chkconfig --level 2345 sshd on
[root@mylinux ~]# service sshd start
[root@mylinux ~]# /etc/init.d/sshd stop
停止 sshd:                                                [確定]
[root@mylinux ~]# /etc/init.d/sshd start
正在啟動(dòng) sshd:                                            [確定]
[root@mylinux ~]# /etc/init.d/sshd status
openssh-daemon (pid  19535) 正在運(yùn)行...

2、openssh配置文件

  • openssh配置文件

 openssh的主要配置文件有兩個(gè):/etc/ssh/ssh_config和/etc/ssh/sshd_config,它們分別用于配置openssh客戶端以及服務(wù)器端。此外,/etc/ssh目錄中還有一些其他的系統(tǒng)級(jí)配置文件,其中各配置文件的名稱以及功能說明為:

moduli                 #配置用于構(gòu)建安全傳輸層所必須的秘鑰組      
ssh_config             #系統(tǒng)級(jí)的SSH客戶端配置文件
sshd_config            #sshd守護(hù)進(jìn)程的配置文件
ssh_host_dsa_key       #sshd進(jìn)程的DSA私鑰
ssh_host_dsa_key.pub   #sshd進(jìn)程的DSA公鑰
ssh_host_key           #SSH1版本所使用的RSA私鑰
ssh_host_key.pub       #SSH1版本所使用的RSA公鑰
ssh_host_rsa_key       #SSH2版本所使用的RSA私鑰
ssh_host_rsa_key.pub   #SSH2版本所使用的RSA公鑰

服務(wù)器配置文件/etc/ssh/sshd_config

 /etc/ssh/sshd_config是openssh服務(wù)器的配置文件,通過更改該文件中的配置可以改變sshd進(jìn)行的運(yùn)行屬性。該文件中每一行都是用'選項(xiàng)   值'的格式,其中'選項(xiàng)'不區(qū)分大小寫。

[root@promote ssh]# cat sshd_config 
#       $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $
# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.
#Port 22                                #sshd監(jiān)聽端口,默認(rèn)為22
#AddressFamily any
#ListenAddress 0.0.0.0                  #sshd服務(wù)綁定的IP地址
#ListenAddress ::
# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2                              #默認(rèn)只用2.*版本的ssh協(xié)議
# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key          #ssh2版本的秘鑰存放位置
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key      #ssh3版本的RSA秘鑰存放位置
#HostKey /etc/ssh/ssh_host_dsa_key      #ssh3版本的DSA秘鑰存放位置
# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h             #秘鑰每隔1小時(shí)生成一次
#ServerKeyBits 1024                     #ssh服務(wù)器秘鑰的位數(shù)
# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH                    #設(shè)置sshd發(fā)送到syslog所使用的日志類型
SyslogFacility AUTHPRIV                 #默認(rèn)為AUTHPRIV
#LogLevel INFO                          #syslog日志等級(jí)
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin yes                    #如果為yes則允許root用戶使用ssh登錄,no則不允許
#設(shè)置sshd在接受登錄請(qǐng)求前是否檢查用戶的主目錄以及rhost文件的權(quán)限和所有者等信息
#StrictModes yes                        
#MaxAuthTries 6                         #設(shè)置最多允許6次登錄失敗
#MaxSessions 10                         #設(shè)置最大連接數(shù)為10 
#RSAAuthentication yes                  #是否允許RSA驗(yàn)證 
#PubkeyAuthentication yes               #是否允許公鑰驗(yàn)證
#AuthorizedKeysFile     .ssh/authorized_keys     #公鑰文件的存放位置
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no               #設(shè)置sshd在進(jìn)行RhostsRSAAuthentication驗(yàn)證時(shí)是否信任用戶的'~/.ssh/known_hosts'文件       
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes                      #驗(yàn)證時(shí)是否使用'~/.rhosts 和 ~/.shosts'文件
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes             #設(shè)置是否需要密碼驗(yàn)證
# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no
# Kerberos options                     #Kerberos 驗(yàn)證
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes
# GSSAPI options                       #GSSAPI 驗(yàn)證
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no                  #清除驗(yàn)證信息
# Set this to 'yes' to enable PAM authentication, account processing, 
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no        
UsePAM yes                             #是否使用PAM驗(yàn)證   
# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
#AllowAgentForwarding yes              #是否允許TCP轉(zhuǎn)發(fā)
#AllowTcpForwarding yes                
#GatewayPorts no                        
#X11Forwarding no                      #設(shè)置sshd是否允許x11轉(zhuǎn)發(fā)  
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes                      #TCP活動(dòng)保持
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0                 #客戶端活動(dòng)間隔時(shí)間
#ClientAliveCountMax 3                 #活動(dòng)客戶端的最大數(shù)量
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid             #保存進(jìn)程ID號(hào)的文件位置
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
# no default banner path
#Banner none
# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       ForceCommand cvs server

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

[root@promote home]# cat /etc/ssh/ssh_config 
#       $OpenBSD: ssh_config,v 1.25 2009/02/17 01:28:32 djm Exp $
# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.
# Configuration data is parsed as follows:     #配置選項(xiàng)生效的優(yōu)先級(jí)
#  1. command line options                     #1表示命令行選項(xiàng)   
#  2. user-specific file                       #2表示用戶指定文件
#  3. system-wide file                         #3表示系統(tǒng)范圍的文件
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.
# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.
# Host *                                      #適用的計(jì)算機(jī)范圍,'*'表示全部
#   ForwardAgent no                           #連接是否經(jīng)過驗(yàn)證代理轉(zhuǎn)發(fā)給遠(yuǎn)程計(jì)算機(jī)
#   ForwardX11 no                             #設(shè)置是否自動(dòng)重定向x11連接
#   RhostsRSAAuthentication no                #設(shè)置是否使用RSA進(jìn)行rhosts的安全驗(yàn)證
#   RSAAuthentication yes                     #設(shè)置是否使用RSA進(jìn)行安全驗(yàn)證
#   PasswordAuthentication yes                #設(shè)置是否需要密碼驗(yàn)證
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no                            #如果為yes,則禁止交互輸入密碼是的提示信息
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa            #RSA安全驗(yàn)證文件的位置
#   IdentityFile ~/.ssh/id_dsa            #DSA安全驗(yàn)證文件的位置
#   Port 22                               #服務(wù)器端口
#   Protocol 2,1                          #使用的ssh協(xié)議 
#   Cipher 3des                           #加密密碼 
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#   EscapeChar ~                          #設(shè)置EscapeChar字符 
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
Host *
        GSSAPIAuthentication yes
# If this option is set to yes then remote X11 clients will have full access
# to the original X11 display. As virtually no X11 client supports the untrusted
# mode correctly we set this to yes.
        ForwardX11Trusted yes                    #是否允許轉(zhuǎn)發(fā)x11會(huì)話
# Send locale-related environment variables      #局部環(huán)境變量
        SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES 
        SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT 
        SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE
        SendEnv XMODIFIERS

3、ssh/scp相關(guān)命令的使用

  • SSH遠(yuǎn)程登錄

 SSH是openssh所提供的加密方式的遠(yuǎn)程登錄程序,可以替代傳統(tǒng)不安全的Telnet、rsh等程序。使用SSH登錄Linux服務(wù)器后可以使用操作系統(tǒng)的所有功能,這與Telnet沒有區(qū)別,但是SSH為客戶端和服務(wù)器之間建立了加密的數(shù)據(jù)傳送通道,更加安全和可靠。命令格式為:

ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D
         [bind_address:]port] [-e escape_char] [-F configfile] [-I pkcs11]
         [-i identity_file] [-L  [bind_address:]port:host:hostport]
         [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-R
         [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port] [-w
         local_tun[:remote_tun]] [user@]hostname [command]

常用命令選項(xiàng):

 -1:強(qiáng)制只使用SSH1版本協(xié)議

 -2:強(qiáng)制只使用SSH2版本協(xié)議

 -4:強(qiáng)制只是用IPv4地址

 -6:強(qiáng)制只是用IPv6地址

 -A:?jiǎn)⒂谜J(rèn)證代理連接的轉(zhuǎn)發(fā)

 -a:禁止認(rèn)證代理連接的轉(zhuǎn)發(fā) 

 -b bind_address:使用bind_address作為連接的源地址

 -C:壓縮所有數(shù)據(jù)

 -D [bind_address:]port:指定本地動(dòng)態(tài)應(yīng)用級(jí)別端口轉(zhuǎn)發(fā)

 -g:允許遠(yuǎn)程主機(jī)連接本地轉(zhuǎn)發(fā)端口

 -l login_name:指定SSH登錄遠(yuǎn)程主機(jī)的用戶 

 -p port:指定連接的端口

 -q:安靜模式,忽略所有的警告信息

 -V:顯示版本信息

 -v:顯示調(diào)試信息

 -X:允許X11連接轉(zhuǎn)發(fā)

 -x:禁止X11連接轉(zhuǎn)發(fā)

[root@promote home]# ifconfig    #查看當(dāng)前主機(jī)IP
eth0      Link encap:Ethernet  HWaddr 00:0C:29:B7:AB:D0  
          inet addr:192.168.191.128  Bcast:192.168.191.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feb7:abd0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1002 errors:0 dropped:0 overruns:0 frame:0
          TX packets:669 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:90190 (88.0 KiB)  TX bytes:89614 (87.5 KiB)
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:113 errors:0 dropped:0 overruns:0 frame:0
          TX packets:113 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:18338 (17.9 KiB)  TX bytes:18338 (17.9 KiB)
[root@promote home]# ssh 192.168.191.129      #連接遠(yuǎn)程主機(jī)192.168.191.129
The authenticity of host '192.168.191.129 (192.168.191.129)' can't be established.
RSA key fingerprint is c6:4b:1c:ca:5b:fd:9f:6e:7f:0a:20:59:9d:79:94:3f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.191.129' (RSA) to the list of known hosts.
reverse mapping checking getaddrinfo for promote.cache-dns.local [192.168.191.129] failed - POSSIBLE BREAK-IN ATTEMPT!
root@192.168.191.129's password: 
Last login: Wed May 17 03:53:02 2017 from 192.168.191.1   #連接成功
[root@promote ~]# ifconfig                                #查看連接后的主機(jī)IP
eth0      Link encap:Ethernet  HWaddr 00:0C:29:F0:56:04  
          inet addr:192.168.191.129  Bcast:192.168.191.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fef0:5604/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:57 errors:0 dropped:0 overruns:0 frame:0
          TX packets:51 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:7404 (7.2 KiB)  TX bytes:6924 (6.7 KiB)
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
  • 使用scp進(jìn)行遠(yuǎn)程文件復(fù)制

   scp的全稱為secure copy(安全性復(fù)制),可以實(shí)現(xiàn)與rcp服務(wù)一樣的遠(yuǎn)程文件復(fù)制功能。但由于scp是基于ssh協(xié)議,實(shí)現(xiàn)了數(shù)據(jù)的加密,所以它比傳統(tǒng)的rcp更加安全可靠,其命令格式為:

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit]
         [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ...
         [[user@]host2:]file2

常用命令選項(xiàng):

 -1:強(qiáng)制只使用SSH1版本協(xié)議

 -2:強(qiáng)制只使用SSH2版本協(xié)議

 -4:強(qiáng)制只是用IPv4地址

 -6:強(qiáng)制只是用IPv6地址

 -C:壓縮所有數(shù)據(jù)

 -l:限制傳輸速率,單位為KB/秒

 -P port:指定連接的端口

 -r:遞歸方式復(fù)制目錄所有內(nèi)容

 -v:調(diào)試方式,顯示更多的輸出信息 

遠(yuǎn)程復(fù)制單個(gè)文件

[root@mylinux ~]# scp mbr.dmp root@192.168.191.129:/home
reverse mapping checking getaddrinfo for promote.cache-dns.local [192.168.191.129] failed - POSSIBLE BREAK-IN ATTEMPT!
root@192.168.191.129's password: 
mbr.dmp                                                100%  512     0.5KB/s   00:00

遠(yuǎn)程復(fù)制整個(gè)目錄

[root@mylinux ~]# scp -r /etc/yum.repos.d root@192.168.191.129:/home/
reverse mapping checking getaddrinfo for promote.cache-dns.local [192.168.191.129] failed - POSSIBLE BREAK-IN ATTEMPT!
root@192.168.191.129's password: 
epel-testing.repo                                      100% 1056     1.0KB/s   00:00   
CentOS-Media.repo                                      100%  630     0.6KB/s   00:00   
epel.repo                                              100%  957     0.9KB/s   00:00   
CentOS-Base.repo                                       100% 1926     1.9KB/s   00:00   
CentOS-Debuginfo.repo                                  100%  638     0.6KB/s   00:00   
CentOS-Vault.repo                                      100% 3664     3.6KB/s   00:00

使用通配符

[root@promote home]# scp -r /etc/httpd/* root@192.168.191.129:/home/ 
reverse mapping checking getaddrinfo for promote.cache-dns.local [192.168.191.129] failed - POSSIBLE BREAK-IN ATTEMPT!
root@192.168.191.129's password: 
magic                                                  100%   13KB  12.8KB/s   00:00   
httpd.conf                                             100%   34KB  33.6KB/s   00:00   
php.conf                                               100%  674     0.7KB/s   00:00   
README                                                 100%  392     0.4KB/s   00:00   
welcome.conf                                           100%  299     0.3KB/s   00:00   
access_log-20170512                                    100%   34KB  34.2KB/s   00:00   
error_log-20170512                                     100% 3278     3.2KB/s   00:00   
error_log                                              100%    0     0.0KB/s   00:00   
access_log                                             100%    0     0.0KB/s   00:00   
mod_proxy_ftp.so                                       100%   35KB  34.8KB/s   00:00   
mod_setenvif.so                                        100%   14KB  14.2KB/s   00:00   
mod_log_config.so                                      100%   31KB  30.5KB/s   00:00   
mod_cgid.so                                            100%   39KB  39.0KB/s   00:00   ...

關(guān)于SSH的優(yōu)化方式 

1、Only Use SSH Protocol 2

2、Limit Users' SSH Access

  AllowUsers 白名單 (二選一)

  DenyUsers 黑名單

3、Configure Idle Log Out Timeout Interval

  ClientAliveInterval 300

  ClientAliveCountMax 0      設(shè)定空閑會(huì)話超時(shí)時(shí)長;

4、Firewall SSH Port #22     使用iptables設(shè)置ssh服務(wù)安全訪問策略;

5、Change SSH Port and Limit IP Binding

  Port 300勿使用默認(rèn)22端口;

  ListenAddress 192.168.1.5

  ListenAddress 202.54.1.5

6、Use Strong SSH Passwords and Passphrase    使用足夠長、足夠復(fù)雜的密碼,且定期更換

    genpasswd() {

    local l=$1

           [ "$l" == "" ] && l=20

          tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs}

7、Use Public Key Based Authentication使用公鑰認(rèn)證

8、Disable Empty Passwords

9、Thwart SSH Crackers (Brute Force Attack)

    google: ssh best practice

10、Rate-limit Incoming Port # 22 Connections    限制ssh訪問頻度;

11、Use Log Analyzer                             記錄好日志,經(jīng)常做日志分析

關(guān)于如何進(jìn)行遠(yuǎn)程連接與openssh就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI