RHEL 4 OpenSSH的配置使用

一、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

二、OpenSSh服務的啓動與中止:
[root@www ~]# chkconfig --list sshd
sshd            0:關閉  1:關閉  2:啓用  3:啓用  4:啓用  5:啓用  6:關閉
[root@www ~]# service sshd start
[root@www ~]# service sshd stop

三、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

四、基於口令的客戶端登錄(客戶端用服務器端已存在的帳號登錄到服務器):
[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 ~]$

五、SSH的用戶目錄:
[root@lwh ~]# ls .ssh/
known_hosts                       //該文件用於保存當前用戶登錄過的全部的SSH服務器的RSA密鑰,這些密鑰都是用戶在第一次登錄SSh服務器時,用輸入yes時保存下來的。

六、基於密鑰的客戶端登錄:
[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 ~]#

七、其餘設置: //不容許以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:
相關文章
相關標籤/搜索