您的位置 首页 > 数码极客

如何查看sshd_config配置信息

在上节,我们学习了网卡的配置,把网络配置好之后,接下来,我们就要开始配置我们的 SSH 远程连接了,毕竟我们不可能时时可以使用桌面或远程桌面的方式做运维。因此我们要学习一下,如何使用我们工具,通过 SSH 的连接方式,连接我们的服务器,对服务器进行运维。

本节内容,要分两部分来讲解。本节内容是以 CentOS 6的配置来当实例。其它的版本,可能会出现不一样的设置(相差很小小),不过 CentOS 8变化会大一点。

一、服务器设置

1、查看是否已经安装 ssh(openssh-server),已安装会出现已经安装的ssh版本信息,如果没有,则会提示no found

[chenmz@localhost ~]$ yum list installed | grep openssh-server o 5.3 @anaconda-Cen [chenmz@localhost ~]$

2、没有安装,使用命令在线安装。一般情况下,Linux最小安装与 WEB版本默认没有安装,其它版本几乎都会安装,有些在安装系统时,选择功能时,也会漏选的情况没有安装。

[chenmz@localhost ~]$ yum install openssh-server

3、安装完成后,开始配置 sshd_config文件(配置文件目录/etc/ssh/sshd_config),可以使用我们之前学习过的命令 vim/vi 来编辑配置文件,当然如果怕错,可以使用cp命令备份一份出来,改得不知道怎么办了,可以恢复回来!(这个很重要,也要习惯做这个动作,特别是我们对系统的文件进行修改时,都要习惯做备份,万一真的出了什么问题,又找不出来原因,可以通过恢复初始的文件来解决。)

备份命令:

[root@localhost network-scripts]# cp sshd_config //备份一个[root@localhost network-scripts]# cd /etc/ssh/ //进入配置文件目录 [root@localhost ssh]# ll 总用量 164 -rw-------. 1 root root 125811 11月 23 2013 moduli -rw-r--r--. 1 root root 2047 11月 23 2013 ssh_config //客户端配置文件(不用管) -rw-------. 1 root root 3896 7月 2 2020 sshd_config //服务器配置文件(要配置的文件) -rw-------. 1 root root 3881 7月 1 2020 sshd_config~ -rw-------. 1 root root 3879 7月 1 2020 //要是怕错,可以先cp备份一份 -rw-------. 1 root root 668 7月 13 2015 ssh_host_dsa_key -rw-r--r--. 1 root root 590 7月 13 2015 -rw-------. 1 root root 963 7月 13 2015 ssh_host_key -rw-r--r--. 1 root root 627 7月 13 2015 -rw-------. 1 root root 1679 7月 13 2015 ssh_host_rsa_key -rw-r--r--. 1 root root 382 7月 13 2015 [root@localhost ssh]# vim 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 //必开,这个是连接的端口,默认22,建议修改成高位数 #AddressFamily any ListenAddress 0.0.0.0 //必开,监听地址 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 //必开,这个是协议2,Centos 7以上默认只有2开可以连接 # HostKey for protocol version 1 #HostKey /etc/ssh/ssh_host_key # HostKeys for protocol version 2 #HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_dsa_key # Lifetime and size of ephemeral version 1 server key #KeyRegenerationInterval 1h #ServerKeyBits 1024 # Logging # obsoletes QuietMode and FascistLogging #SyslogFacility AUTH SyslogFacility AUTHPRIV #LogLevel INFO # Authentication: #LoginGraceTime 2m PermitRootLogin no //允许root用户远程登陆,必开,但yes设为no,有关安全 #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 #RSAAuthentication yes #PubkeyAuthentication yes #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 # Don't read the user's ~/.rhosts and ~/.shosts files #IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no //允许空密码登陆,建议关闭 PasswordAuthentication yes //默认已开,允许使用密码验证登陆 # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes ChallengeResponseAuthentication no # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no #KerberosUseKuserok yes # GSSAPI options #GSSAPIAuthentication no GSSAPIAuthentication yes //建议开户,基于GSSAPI的用户认证 #GSSAPICleanupCredentials yes GSSAPICleanupCredentials yes #GSSAPIStrictAcceptorCheck yes //建议开户,退出登陆清缓存 #GSSAPIKeyExchange no # 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 # 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 #AllowTcpForwarding yes #GatewayPorts no #X11Forwarding no X11Forwarding yes //建议开启转发 #X11DisplayOffset 10 #X11UseLocalhost yes #PrintMotd yes #PrintLastLog yes #TCPKeepAlive yes #UseLogin no #UsePrivilegeSeparation yes #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #ShowPatchLevel no #UseDNS yes #PidFile /var/run #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

4、配置文件的重点说明(符合基本的安全设置,如果需要更强的安全,得再深入去学习 ssh相关配置才可以)。

主要你把下面的9项开启并设置好,那服务的SSH配置就基本已经完成。可以使用客户端来远程连接了!

Port 22 //必开,这个是连接的端口,默认22,建议修改成高位数 ListenAddress 0.0.0.0 //必开,监听地址 ListenAddress :: //必开,监听地址 Protocol 2 //必开,这个是协议2,Centos 7以上默认只有2开可以连接 PermitRootLogin no //允许root用户远程登陆,必开,但yes设为no,有关安全 PasswordAuthentication yes //默认已开,允许使用密码验证登陆 GSSAPIAuthentication yes //建议开启,基于GSSAPI的用户认证 GSSAPICleanupCredentials yes //建议开启,退出清缓存 X11Forwarding yes //建议开启转发

5、防火墙的设置

默认的情况下,防火墙是关闭的,不用设置,如果你上面的设置要是都开启了,还是连接不上,可以查看 一下防火墙的设置,特别是你设置的端口不是常用的话,更要注意这里!

使用命令给防火墙加上放行端口

iptables -A INPUT -p tcp --dport 端口号-j ACCEPT

二、工具设置

直接上个图即可

设置服务器地址:

端口号:

然后就可以下一步就是输入帐号与密码(用户如果设置,请翻查之前的文章)

登陆成功后

要使用root权限怎么办呢?

直接使用命令su来切换即可!是不是很方便呢?

su - root

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“如何查看sshd_config配置信息,sshd,config配置”边界阅读