SSH:Secure SHell

由IETF的网络工作小组(Network Working Group)所制定;SSH为创建在应用层和传输层基础上的安全协议。传统的网络服务程序,如FTP、POP和Telnet其本质上都是不安全的;因为它们在网络上用明文传送数据、用户帐号和用户口令,很容易受到中间人(man-in-the-middle)***方式的***。就是存在另一个人或者一台机器冒充真正的服务器接收用户传给服务器的数据,然后再冒充用户把数据传给真正的服务器。而SSH是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用SSH协议可以有效防止远程管理过程中的信息泄露问题。通过SSH可以对所有传输的数据进行加密,也能够防止DNS欺骗和IP欺骗。SSH之另一项优点为其传输的数据是经过压缩的,所以可以加快传输的速度。SSH有很多功能,它既可以代替Telnet,又可以为FTP、POP、甚至为PPP提供一个安全的“通道”。 ——《维基百科》

sshv1 有致命缺陷

sshv2  目前广泛使用

openSSH  开源的SSH

使用的rpm包:openssh:提供客户端(scp,ssh-keygen)组件

               openssh-clients:ssh,slogin,ssh-agent,sftp

               openssh-askpass,openssh-askpass-gnome跟ssh-agent通信的一个组件。

               openssh-server 服务器组件 

所依赖的组件:openssl

openssh authentication:基于口令的认证

                       基于RSA/DSA 密钥的认证

                       kerberos 基于令牌的认证

生成一对密钥文件:

[root@server27 .ssh]# ssh-keygen -t 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:

4d:79:37:c6:fe:d6:1c:ae:54:61:0a:65:24:82:4a:76 root@server27.example.com

[root@server27 .ssh]# ls

authorized_keys2  id_rsa  id_rsa.pub  known_hosts

ssh-copy-id 实现将公钥文件拷贝到远程服务器上的功能。

[root@server27 .ssh]# ssh-copy-id -i /root/.ssh/id_rsa root@192.168.0.39

-i 指定私钥文件(命令会拷贝私钥所对应的公钥文件)

0

root@192.168.0.39's password:

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

  .ssh/authorized_keys

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

看,不用输密码可以直接登录了:

wps_clip_p_w_picpath-13372

Openssh  C/S 架构

客户端配置文件:/etc/ssh/ssh_config

服务器端配置文件:/etc/ssh/sshd_config

启动脚本:/etc/init.d/sshd

wps_clip_p_w_picpath-30935

ssh_host_dsa_key.pub ssh_host_dsa_key

ssh_host_rsa_key.pub  ssh_host_rsa_key

sshv2 所使用

ssh_host_key.pub   ssh_host_key         

sshv1所使用

PS:主机公钥,跟用户登录没关系

ssh接受/etc/motd里边的信息作为登录信息。

SSH端口转发:ssh和sshd联合使用可以实现,类似于一个隧道,在这个隧道里能够转发明文协议,以此实现对某些协议的加密功能。只能转发基于TCP的连接。

X11 Forwarding

本地开启了图形界面,当登录到远程主机上,可以在本地图形界面上执行远端主机上的图形窗口

启动图形界面  startx &

[root@server27 ssh]# ssh -X 192.168.0.39

Last login: Thu Mar  3 16:48:26 2011 from server27.example.com

[root@station39 ~]# system-config-date