ubuntu ssh config(ubuntu安装ssh命令)
今天给各位分享ubuntu ssh config的知识,其中也会对ubuntu安装ssh命令进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
如何开启ubuntu的SSH服务
解决方法:
在Ubuntu下开启SSH首先要确认是否配置了IP,如果没有用以下命令进行配置:
1.sudo ifconfig eth0 192.168.0.3 netmask 255.255.255.0//配置你的eth0网卡的ip地址和子网掩码
2. duso route default gw 192.168.0.1//配置默认路由
开启ssh服务
1.查看是否有sshd_config
cat/etc/ssh/sshd_config//查看是否有sshd_config文件
2.如果没有进行安装
sudo apt-get install opensshd-server//安装sshd-server,Ubuntu缺省安装了openssh-client,如果没有安装,用apt-get install进行安装即可。
3.查看sshsever是否启动
ps-e|grep ssh
1207? 00:00:00 ssh-agent
21834? 00:00:00 sshd
如果看到sshd则表示sshserver已经启动,如果只有ssh-agent,则表示没有启动,用
sudo/etc/init.d/ssh start启动sshserver
4.ssh-server的配置文件位于/etc/ssh/sshd_config,在这里可以定义SSH的服务端口,默认端口是22,你可以自己定义成其他端口号,如222。然后用以下命令重启SSH服务:
sudo/etc/init.d/ssh restart
5.还可以用sudo netstart-tlp命令来检测,如果看到:
tcp6 0 0 [::]:ssh [::]:*
就表示sshserver启动正常。
通过客户端就可以访问了。
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使用root账户ssh连接失败
问题如下:
在使用ssh root@ubuntu-server进行连接时,系统提示“Permission denied,please try again”。
许多在线解决方案建议编辑/etc/ssh/sshd_config文件,并将其中的PermitRootLogin设置为yes,但这种方法未能解决我的问题,问题依旧存在。
经过反复尝试,我找到了以下有效解决方法:
第一步:修改/etc/ssh/sshd_config文件。
第二步:重启ssh服务。
第三步:修改root密码,这可能是解决问题的关键步骤。
第四步:使用ssh进行连接。
完成以上步骤后,问题得到解决。