ubuntu ssh 修改(linux 安装ssh)
大家好,感谢邀请,今天来为大家分享一下ubuntu ssh 修改的问题,以及和linux 安装ssh的一些困惑,大家要是还不太明白的话,也没有关系,因为接下来将为大家分享,希望可以帮助到大家,解决大家的问题,下面就开始吧!
ubuntu修改了ssh配置后 putty 还是出现access denied
你可以从以下几点查看实验下。
首先,先备份一下配置文件。
mkdir~/backup
cp/etc/ssh/ssh_config~/backup/ssh_config
第二步,编辑文件:
vi/etc/ssh/ssh_config
使用“/”搜搜看下Allow/Deny开头的项目,全部注释掉。(我查看了下,有些文章说AllowUsers参数会限制访问用户,需要在后面添加root,才能使用root账户ssh登陆,但我在我的centos7的ssh_config文件中未看到此参数,虽然有一些其他Allow\Deny开头的参数,不过全部都是被注释状态。可以参考最后我的sshd_config文件。)
修改完成后,重启服务/etc/init.d/ssh start(参考的百度出来的文章结果,我实际实验结果是:守护进程里并没有ssh,无法运行此命令,chkconfig里也没有sshd进程,service也无法重启ssh,所以我直接reboot了系统)
如果,依然不行进行下一步。
第三步,同网段内其他windows主机打开cmd,查看主机ssh端口(如果修改了默认端口,得自行把22修改为正确端口)是否正常。
win+r,输入cmd
ping(ubuntu主机IP地址)#首先要保证网络通
telnet(ubuntu主机IP地址)22#查看端口是否通
如果正常,应该显示类似“SSH-2.0-OpenSSH_6.6.1”的消息,或者是纯黑屏,再次点击回车断开连接。
第四步,如果上一步显示不正常,可能是防火墙设置问题,关闭或设置防火墙
ufw disable(方法一:关闭防火墙)
ufw allow 22/tcp(方法二:打开端口22)
(注:我用的centos采用的是最小化安装,未安装防火墙,这一步骤是我参考的网上资料,未进行实验。具体可自行百度。)
最后附上我的ssh_config文件。
#$OpenBSD:sshd_config,v1.932014/01/1005:59:19djmExp$
#Thisisthesshdserversystem-wideconfigurationfile.See
#sshd_config(5)formoreinformation.
#ThissshdwascompiledwithPATH=/usr/local/bin:/usr/bin
#Thestrategyusedforoptionsinthedefaultsshd_configshippedwith
#OpenSSHistospecifyoptionswiththeirdefaultvaluewhere
#possible,butleavethemcommented.Uncommentedoptionsoverridethe
#defaultvalue.
#IfyouwanttochangetheportonaSELinuxsystem,youhavetotell
#SELinuxaboutthischange.
#semanageport-a-tssh_port_t-ptcp#PORTNUMBER
#
#Port22
#AddressFamilyany
#ListenAddress0.0.0.0
#ListenAddress::
#Thedefaultrequiresexplicitactivationofprotocol1
#Protocol2
#HostKeyforprotocolversion1
#HostKey/etc/ssh/ssh_host_key
#HostKeysforprotocolversion2
HostKey/etc/ssh/ssh_host_rsa_key
#HostKey/etc/ssh/ssh_host_dsa_key
HostKey/etc/ssh/ssh_host_ecdsa_key
HostKey/etc/ssh/ssh_host_ed25519_key
#Lifetimeandsizeofephemeralversion1serverkey
#KeyRegenerationInterval1h
#ServerKeyBits1024
#Ciphersandkeying
#RekeyLimitdefaultnone
#Logging
#obsoletesQuietModeandFascistLogging
#SyslogFacilityAUTH
SyslogFacilityAUTHPRIV
#LogLevelINFO
#Authentication:
#LoginGraceTime2m
#PermitRootLoginyes
#StrictModesyes
#MaxAuthTries6
#MaxSessions10
#RSAAuthenticationyes
#PubkeyAuthenticationyes
#Thedefaultistocheckboth.ssh/authorized_keysand.ssh/authorized_keys2
#butthisisoverriddensoinstallationswillonlycheck.ssh/authorized_keys
AuthorizedKeysFile.ssh/authorized_keys
#AuthorizedPrincipalsFilenone
#AuthorizedKeysCommandnone
#AuthorizedKeysCommandUsernobody
#Forthistoworkyouwillalsoneedhostkeysin/etc/ssh/ssh_known_hosts
#RhostsRSAAuthenticationno
#similarforprotocolversion2
#HostbasedAuthenticationno
#Changetoyesifyoudon'ttrust~/.ssh/known_hostsfor
#RhostsRSAAuthenticationandHostbasedAuthentication
#IgnoreUserKnownHostsno
#Don'treadtheuser's~/.rhostsand~/.shostsfiles
#IgnoreRhostsyes
#Todisabletunneledcleartextpasswords,changetonohere!
#PasswordAuthenticationyes
#PermitEmptyPasswordsno
PasswordAuthenticationyes
#Changetonotodisables/keypasswords
#ChallengeResponseAuthenticationyes
ChallengeResponseAuthenticationno
#Kerberosoptions
#KerberosAuthenticationno
#KerberosOrLocalPasswdyes
#KerberosTicketCleanupyes
#KerberosGetAFSTokenno
#KerberosUseKuserokyes
#GSSAPIoptions
GSSAPIAuthenticationyes
GSSAPICleanupCredentialsno
#GSSAPIStrictAcceptorCheckyes
#GSSAPIKeyExchangeno
#GSSAPIEnablek5usersno
#Setthisto'yes'toenablePAMauthentication,accountprocessing,
#andsessionprocessing.Ifthisisenabled,PAMauthenticationwill
#beallowedthroughtheChallengeResponseAuthenticationand
#PasswordAuthentication.DependingonyourPAMconfiguration,
#PAMauthenticationviaChallengeResponseAuthenticationmaybypass
#thesettingof"PermitRootLoginwithout-password".
#IfyoujustwantthePAMaccountandsessioncheckstorunwithout
#PAMauthentication,thenenablethisbutsetPasswordAuthentication
#andChallengeResponseAuthenticationto'no'.
#WARNING:'UsePAMno'isnotsupportedinRedHatEnterpriseLinuxandmaycauseseveral
#problems.
UsePAMyes
#AllowAgentForwardingyes
#AllowTcpForwardingyes
#GatewayPortsno
X11Forwardingyes
#X11DisplayOffset10
#X11UseLocalhostyes
#PermitTTYyes
#PrintMotdyes
#PrintLastLogyes
#TCPKeepAliveyes
#UseLoginno
UsePrivilegeSeparationsandbox#Defaultfornewinstallations.
#PermitUserEnvironmentno
#Compressiondelayed
#ClientAliveInterval0
#ClientAliveCountMax3
#ShowPatchLevelno
#UseDNSyes
#PidFile/var/run/sshd.pid
#MaxStartups10:30:100
#PermitTunnelno
#ChrootDirectorynone
#VersionAddendumnone
#nodefaultbannerpath
#Bannernone
#Acceptlocale-relatedenvironmentvariables
AcceptEnvLANGLC_CTYPELC_NUMERICLC_TIMELC_COLLATELC_MONETARYLC_MESSAGES
AcceptEnvLC_PAPERLC_NAMELC_ADDRESSLC_TELEPHONELC_MEASUREMENT
AcceptEnvLC_IDENTIFICATIONLC_ALLLANGUAGE
AcceptEnvXMODIFIERS
#overridedefaultofnosubsystems
Subsystemsftp/usr/libexec/openssh/sftp-server
#Exampleofoverridingsettingsonaper-userbasis
#MatchUseranoncvs
#X11Forwardingno
#AllowTcpForwardingno
#PermitTTYno
#ForceCommandcvsserver
ubuntu 用ssh远程修改配置文件
修改ssn连接的端口ssh端口默认为22,我们可以通过修改配置文件改为一个非著名的端口,比如2222,vⅰm/etc/ssh/sshd-config用vim编辑器打开sshd-config,把22...禁止root用户直接ssh连接root这个账号是所有人都知道并且拥有最高权限的账号。直接暴露在网络中不大安全。我们可以禁止ssh使用root连接,同样只需要修改ssh的配置文件即可。啊
Ubuntu:修改ssh端口并开放防火墙
远程运维中,服务器稳定性是关键。本文记录了在Ubuntu系统中修改SSH端口并启用防火墙的过程。首先,我们需将默认SSH端口22修改为其他端口,比如23,操作步骤是修改/etc/ssh/sshd_config文件中的配置项。接着,启动防火墙,以确保23端口能够被访问。在Ubuntu中,ufw防火墙提供了简化操作的命令行工具,通过命令可以开启防火墙并将其状态设置为允许特定端口访问。使用ufw allow 23/tcp命令允许SSH端口通过防火墙。为了确保所有设置生效,需重启SSH服务。修改端口后,使用新端口尝试连接服务器,验证连接成功。
本文强调了在进行防火墙配置和端口修改时,应遵循网络安全最佳实践,仅允许必要的端口和服务通过防火墙。确保系统安全,避免不必要的风险。通过本文记录的步骤,运维人员可以在确保系统稳定性的前提下,灵活调整网络访问策略。