Linux远程连接工具-OpenSSH

在我们日常管理与维护服务器个过程中,我们都需要使用远程连接工具,今天我们就一同来总结下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. [email protected]’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 #退出登录; logoutConnection to 192.168.0.110 closed. [root@www ~]# ssh [email protected] ls #使用root登录远程主机,执行一次ls命令,返回结果便退出; [email protected]’s password: #第二次连接,就不需要输入yes了,直接输入密码即可; 2.sh anaconda-ks.cfg boot.iso crontabinstall.log install.log.syslog sdb.mbr \temp\testtest1 [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

可是却依旧为对方擦去嘴角的油渍。

Linux远程连接工具-OpenSSH

相关文章:

你感兴趣的文章:

标签云: