1、OpenSSH软件包组成:
[root@www ~]# rpm -qa | grep ssh
openssh-clients-3.9p1-8.RHEL4.24
openssh-3.9p1-8.RHEL4.24
openssh-askpass-3.9p1-8.RHEL4.24
openssh-server-3.9p1-8.RHEL4.24
openssh-askpass-gnome-3.9p1-8.RHEL4.24

2、OpenSSh服务的启动与停止:
[root@www ~]# chkconfig --list sshd
sshd            0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
[root@www ~]# service sshd start
[root@www ~]# service sshd stop

3、OpenSSh服务的配置文件:
[root@www ~]# ll /etc/ssh
总用量 184
-rw-------  1 root root 111892 2007-08-08  moduli
-rw-r--r--  1 root root   1417 2007-08-08  ssh_config                         //客户端的配置文件,当作为客户机使用时,ssh命令将按该配置文件的内容进行设置;
-rw-------  1 root root   3025 2007-08-08  sshd_config                      //服务器端的配置文件,服务端启动时会按照此配置文件的内容进行设置;
-rw-------  1 root root    668  1月 14 01:14 ssh_host_dsa_key              //私钥;
-rw-r--r--  1 root root    590  1月 14 01:14 ssh_host_dsa_key.pub        //公钥
-rw-------  1 root root    515  1月 14 01:14 ssh_host_key
-rw-r--r--  1 root root    319  1月 14 01:14 ssh_host_key.pub
-rw-------  1 root root    887  1月 14 01:14 ssh_host_rsa_key
-rw-r--r--  1 root root    210  1月 14 01:14 ssh_host_rsa_key.pub

4、基于口令的客户端登陆(客户端用服务器端已存在的账号登陆到服务器):
[root@www ~]# iptables -I INPUT 1 -p tcp -s 192.168.100.1 --dport 22 -j ACCEPT   //在服务器端的防火墙插入一条策略规则,即时生效。
[root@lwh ~]# ssh tel@192.168.100.1
The authenticity of host '192.168.100.1 (192.168.100.1)' can't be established.
RSA key fingerprint is b6:0d:d5:77:4f:be:2e:46:90:59:44:6e:ba:52:1c:3b.
Are you sure you want to continue connecting (yes/no)? yes                 //客户端首次登陆时需要在服务器端下载一个RSA密钥到本地的“/用户主目录/.ssh”文件夹里;
tel@192.168.100.2's password:                                                            //并要求输入服务器上tel用户的密码;
[tel@www ~]$

5、SSH的用户目录:
[root@lwh ~]# ls .ssh/
known_hosts                       //该文件用于保存当前用户登陆过的所有的SSH服务器的RSA密钥,这些密钥都是用户在第一次登陆SSh服务器时,用输入yes时保存下来的。

6、基于密钥的客户端登陆:
[root@www ~]# iptables -I INPUT 1 -p tcp -s 192.168.100.1 --dport 22 -j ACCEPT   //同样,在服务器端的防火墙插入一条策略规则。
①、创建用户用于SSH登陆:
[root@lwh ~]# useradd sshuser
[root@lwh ~]# passwd sshuser

②、在客户端生成公钥和私钥对:
[root@lwh ~]# su - sshuser                  //切换用户;    
[sshuser@lwh ~]$ pwd                         //用户当前路径;
/home/sshuser
[sshuser@lwh ~]$ ssh-keygen -t rsa          //生成公钥和私钥对;
Generating public/private rsa key pair.
Enter file in which to save the key (/home/sshuser/.ssh/id_rsa):
Created directory '/home/sshuser/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/sshuser/.ssh/id_rsa.
Your public key has been saved in /home/sshuser/.ssh/id_rsa.pub.
The key fingerprint is:
0c:8d:9e:99:b5:95:32:70:96:6e:1c:38:71:57:4d:cb [email]sshuser@lwh.com[/email]
[sshuser@lwh ~]$ ll .ssh/                      //查看生成的密钥文件;
总用量 16
-rw-------  1 sshuser sshuser 883  2月  5 17:22 id_rsa
-rw-r--r--  1 sshuser sshuser 225  2月  5 17:22 id_rsa.pub

③、将生成的公钥“id_rsa.pub”复制并改名添加到SSH服务器“/想要登陆的账号/.ssh/authorized_keys”
//在SSH服务器相应的目录下新建“.ssh”目录:
[root@www ~]# mkdir /root/.ssh/
//在SSH客户端,用scp命令进行复制:
[sshuser@lwh ~]$ scp ~/.ssh/id_rsa.pub root@192.168.100.2:~/.ssh/authorized_keys       //注意登陆的用户名,拷贝到那个宿主目录下,就在客户端以哪个账号登陆;
The authenticity of host '192.168.100.2 (192.168.100.2)' can't be established.
RSA key fingerprint is fe:88:0f:f6:ac:d4:76:9a:ef:4b:16:28:37:36:ec:93.
Are you sure you want to continue connecting (yes/no)? yes                           
Warning: Permanently added '192.168.100.2' (RSA) to the list of known hosts.
root@192.168.100.2's password:
id_rsa.pub                                                                          100%  225     0.2KB/s   00:00

④、在客户端登陆:
[sshuser@lwh ~]$ ssh root@192.168.100.2                  
Last login: Thu Feb  5 17:17:49 2009 from linserv                    //并没有提示要输入密码;
[root@www ~]#

7、其他设置:
//不允许以root账号登陆服务器在服务器端:
[root@www ~]# vi /etc/ssh/sshd_config
PermitRootLogin no             //在配置文件中加入;
[root@www ~]# service sshd restart
//再次登陆:
[root@lwh ~]# su - sshuser            //sshuser是创建的用于ssh登陆的账号;
[sshuser@lwh ~]$ ssh root@192.168.100.2
root@192.168.100.2's password:                   //输入密码;
Permission denied, please try again.               //提示权限拒绝,可以通过使用普通账号登陆服务器后再切换到root账号来实现远程管理的目的;
root@192.168.100.2's password: