centos cvs server centos镜像

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

linux 远程登录工具哪个好

在我们日常管理与维护服务器个过程中,我们都需要使用远程连接工具,今天我们就一同来总结下Linux常用的安全远程连接工具-OpenSSH。

【远程登录协议】

1、telnet:是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议和主要方式。它为用户提供了在本地计算机上完成远程主

机工作的能力。默认使用的是TCP的23号端口,采用C/S架构,在用户登录的过程中传输的信息都是明文信息,安全无法保障,所以不建议用telnet。

2、ssh:为Secure Shell的缩写,由IETF的网络工作小组所制定;SSH

为建立在应用层和传输层基础上的安全协议。SSH是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用 SSH

协议可以有效防止远程管理过程中的信息泄露问题。默认使用的是TCP的22号端口,也是基于C/S架构,SSH有两个版本v1与v2。

sshv1:基于CRC-32做MAC(消息摘要认证),不安全,强烈建议不使用;

sshv2:基于双方主机的协商选择使用最安全的MAC方式,其有如下特点:1、加密机制及MAC机制由双方协商选定;2、基于DH实现密钥交换,基于RSA或DSA实现身份认证;3、客户端通过检查服务器端的主机密钥来判断是否能够继续通信;

【OpenSSH简述】

OpenSSH是一组用于安全地访问远程计算机的连接工具。它可以作为rlogin、rsh

rcp以及telnet的直接替代品使用。更进一步,其他任何TCP/IP连接都可以通过SSH安全地进行隧道/转发。OpenSSH

对所有的传输进行加密,从而有效地阻止了窃听、连接劫持,以及其他网络级的攻击。OpenSSH由 OpenBSD project维护。

登录过程和使用rlogin或telnet建立的会话非常类似。在连接时,SSH

会利用一个密钥指纹系统来验证服务器的真实性。只有在第一次连接时,用户会被要求输入yes进行确认,之后的连接将会验证预先保存下来的密钥指纹。如果保

存的指纹与登录时接收到的不符,则将会给出警告。指纹保存在~/.ssh/known_hosts中,对于SSHv2指纹,则是

~/.ssh/known_hosts2。

默认情况下,较新版本的OpenSSH只接受SSHv2连接。如果能用版本2则客户程序会自动使用,否则它会返回使用版本1的模式。此外,也可以通

过命令行参数-1或-2来相应地强制使用版本1或2。保持客户端的版本1能力是为了考虑较早版本的兼容性,建议尽量使用版本2。

【SSH服务器和客户端工作流程】

OpenSSH使用C/S架构:

服务端工具(S):sshd

客户端工具(C):ssh命令、putty、xshell、securecrt、sshshellclient;

【OpenSSH客户端组件-ssh】

配置文本:/etc/ssh/ssh_config

使用方法:

ssh [username@] host [COMMAND]或 ssh-l username host [COMMAND]

-p PORT:指定远程服务器端口;

-l username:指定登录远程主机的用户,不指定则使用当前用户;

username@:等同于-l username;

如果设置了COMMAND,表示使用username账户登录远程主机执行一次指定的命令并返回结果,不会停留在远程主机上;

[root@www~]# ssh 192.168.0.110#使用root用户登录;

The authenticity of host'192.168.0.110(192.168.0.110)' can't be established.

RSA key fingerprint is 01:2e:43:cc:bc:1d:f1:e5:f0:f4:89:78:74:a9:49:44.

Are you sure you want to continue connecting(yes/no)? yes#第一次连接,需手动进行确认;

Warning: Permanently added'192.168.0.110'(RSA) to the list of known hosts.

root@192.168.0.110's password:#输入远程主机root账户的密码;

Last login: Mon May 11 16:44:52 2015 from 192.168.0.104

[root@mailCentOS6~]##登录成功了,远程主机名为mailCentOS6;

[root@mailCentOS6~]# ls#显示远程主机root家目录下的文件;

2.sh boot.iso install.log sdb.mbr test1

anaconda-ks.cfg crontab install.log.syslog\temp\test

[root@mailCentOS6~]# exit#退出登录;

logout

Connection to 192.168.0.110 closed.

[root@www~]# ssh root@192.168.0.110 ls#使用root登录远程主机,执行一次ls命令,返回结果便退出;

root@192.168.0.110's password:#第二次连接,就不需要输入yes了,直接输入密码即可;

2.sh

anaconda-ks.cfg

boot.iso

crontab

install.log

install.log.syslog

sdb.mbr

\temp\test

test1

[root@www~]##看到了吗,我们当前并没有登录在远程主机;

【OpenSSH服务器端组件-sshd】

配置文件:/etc/ssh/sshd_config(通过修改此文件可以修改ssh的默认监听端口与其他参数)

服务脚本:/etc/rc.d/init.d/sshd

服务启动|停止|重启:serveice sshd start|stop|restart

脚本配置文件:/etc/sysconfig/sshd

配置参数

# man sshd_config查看配置参数的说明;

# vim/etc/sysconfig/sshd通过编辑配置文件来修改配置参数;

#+空格+文字:以此格式开头的行表示改行为注释说明;

#+文字:以此格式开头的行表示可启用选项,不改变则表示使用该选项的默认设置,反之使用设定值“#”要去掉哦!

例:#Port 22如不去掉#且22不变,表示使用默认的22号端口;

若把#Port 22改成port 7777,表示把sshd的监听端口改成7777;

注意:修改参数与配置后,必须重启服务(service sshd restart).

经常需要修改的参数:

[root@www~]# cat/etc/ssh/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#修改默认监听的端口;

port 7777#把sshd的监听端口改成7777;

#AddressFamily any#监听的地址家族,指定是监听在IPV4上还是IPV6上,any表示所有;

#ListenAddress 0.0.0.0#指定监听的地址(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

# HostKey for protocol version 1

#HostKey/etc/ssh/ssh_host_key#使用shhv1用到的主机密钥;

# 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 yes#是否允许管理员直接登录;

#StrictModes yes

#MaxAuthTries 6#最大密码输入错误次数;

#MaxSessions 10#最大会话个数;

#RSAAuthentication yes#是否允许使用RSA机制来认证;

#PubkeyAuthentication yes

#--------中间不长改变的配置参数略----------

Subsystem sftp/usr/libexec/openssh/sftp-server#表示是否启动sftp功能;

# Example of overriding settings on a per-user basis

#Match User anoncvs

# X11Forwarding no

# AllowTcpForwarding no

# ForceCommand cvs server

sshd认证方式:

1、基于口令的认证;

2、基于密钥的认证;

# ssh-keygen-t rsa用rsa算法生成密钥,默认密钥为id_rsa(私钥), id_rsa.pub(公钥)

# ssh-keygen-f/path/to/somefile-P oldpassword根据现有的密钥文件生成密钥

-f/path/to/somefile:密钥文件保存在的位置;

-P'':指定生成旧密钥时使用的密码;

方法一:把本地主机生成的公钥 id_rsa.pub使用scp复制到远程主机的上,在远程主机使用cat id_rsa.pub>>.ssh/authorized_keys追加该公钥信息,这样就可以实现基于密钥认证的ssh登录;

方法二:# ssh-copy-id-i.ssh/id_rsa.pub USERNAME@HOST

[root@www~]# ssh-keygen-t rsa#用rsa算法生成密钥;

Generating public/private rsa key pair.

Enter file in which to save the key(/root/.ssh/id_rsa):#指定密钥存放路径及名称,一般不用

#修改,直接回车;

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.

The key fingerprint is:

c2:f9:c2:3d:4d:ca:52:39:7a:a7:33:de:42:11:d3:8f root@www.99.com

The key's randomart image is:

+--[ RSA 2048]----+

|.|

| o.|

| o o|

|....E.|

|+ S..|

|. B.=|

|=.B o|

|++=|

|.o+.|

+-----------------+

[root@www~]# ssh-keygen-f.ssh/id_rsa-P''#根据现有密钥文件重新生成密钥;

Generating public/private rsa key pair.

.ssh/id_rsa already exists.

Overwrite(y/n)? y#提示是否确定要覆盖;

Your identification has been saved in.ssh/id_rsa.

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

The key fingerprint is:

bf:55:f0:0b:a5:ee:4e:4a:1d:d3:b1:0e:66:ee:55:9b root@www.99.com

The key's randomart image is:

+--[ RSA 2048]----+

||

||

|. o|

|* o|

| S O=.|

|.* B oo|

| o*+E|

|. B.|

| o.+|

+-----------------+

#-----使用方法一:实现通过密钥文件完成身份验证(不需要输入密码)-----

[root@www~]# scp.ssh/id_rsa.pub root@192.168.0.110:/root/#使用spc命令复制公钥文件到远程

#主机的用户家目录下的.ss/路径下;

root@192.168.0.110's password:#输入登录远程主机的密码;

id_rsa.pub 100% 397 0.4KB/s 00:00#提示复制成功;

[root@mailCentOS6~]# ls.ssh/#验证确认文件复制成功;

id_rsa.pub known_hosts

[root@mailCentOS6~]# touch.ssh/authorized_keys#路径内没有自动验证密钥文件,创建一个;

[root@mailCentOS6~]# cat.ssh/id_rsa.pub>>.ssh/authorized_keys#把公钥追加到自动验证密钥文件;

[root@www~]# ssh 192.168.0.110

Last login: Mon May 11 20:45:10 2015 from 192.168.0.111

[root@mailCentOS6~]##OK了,看到了没有,不用输入密码我们就直接可以远程登录了!!

#-----使用方法二:实现通过密钥文件完成身份验证(不需要输入密码)-----

[root@mailCentOS6~]# rm-f.ssh/authorized_keys#删除原有保存的自动验证密钥文件;

[root@www~]# ssh-copy-id-i.ssh/id_rsa.pub root@192.168.0.110#使用命令自动传输生成自动验证密钥文件;

root@192.168.0.110's password:

Now try logging into the machine, with"ssh'root@192.168.0.110'", and check in:

.ssh/authorized_keys#提示生成的文件;

to make sure we haven't added extra keys that you weren't expecting.

[root@www~]# ssh 192.168.0.110#验证看看是否可以登录;

Last login: Mon May 11 21:02:29 2015 from 192.168.0.111

[root@mailCentOS6~]# ls.ssh/#看到了没有,我们现在已经登录到了mailCentOS6这台主机上了;

authorized_keys known_hosts

【命令补充】

scp:利用ssh协议在主机之间实现安全文件传输的工具

scp SRC1... DEST

分两种情形:

1、源文件在本机,目标为远程主机

# scp/path/to/somefile... USERNAME@HOST:/path/to/somewhere

源可以是目录或文件有多个,目标必须是目录

2、源文件在远程,本地为目标

# scp USERNAME@HOST:/path/to/somewhere/path/to/somewhere

-r:复制目录时使用(实现递归复制),scp默认不能复制目录;

-p:保持源文件的元数据信息,包括mode和timestamp

-q:静默模式,复制过程不显示状态信息;

-p PORT:指定ssh协议监听的端口(远程主机)。

阅读剩余
THE END