Linux Xmanager

OpenSSH

SSHSecureSHellprotocol的簡寫

1OpenSSH軟件包組成:
[root@www~]#rpm-qa|grepssh
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--listsshd
sshd0:
關閉1:關閉2:啓用3:啓用4:啓用5:啓用6:關閉
[root@www~]#servicesshdstart
[root@www~]#servicesshdstop

3
OpenSSh服務的配置文件:
[root@www~]#ll/etc/ssh
總用量184
-rw-------1rootroot1118922007-08-08moduli
-rw-r--r--1rootroot14172007-08-08ssh_config

#客戶端的配置文件,當作爲客戶機使用時,ssh命令將按該配置文件的內容進行設置
-rw-------1rootroot30252007-08-08sshd_config

#服務器端的配置文件,服務端啓動時會按照此配置文件的內容進行設置
-rw-------1rootroot6681
1401:14ssh_host_dsa_key#私鑰
-rw-r--r--1rootroot5901
1401:14ssh_host_dsa_key.pub#公鑰
-rw-------1rootroot5151
1401:14ssh_host_key
-rw-r--r--1rootroot3191
1401:14ssh_host_key.pub
-rw-------1rootroot8871
1401:14ssh_host_rsa_key
-rw-r--r--1rootroot2101
1401:14ssh_host_rsa_key.pub

4
、基於口令的客戶端登陸(客戶端用服務器端已存在的賬號登陸到服務器):
[root@www~]#iptables-IINPUT1-ptcp-s192.168.100.1--dport22-jACCEPT

#在服務器端的防火牆插入一條策略規則,即時生效。
[root@lwh~]#[email protected]
Theauthenticityofhost'192.168.100.1(192.168.100.1)'can'tbeestablished.
RSAkeyfingerprintisb6:0d:d5:77:4f:be:2e:46:90:59:44:6e:ba:52:1c:3b.
Areyousureyouwanttocontinueconnecting(yes/no)?yes

#客戶端首次登陸時需要在服務器端下載一個RSA密鑰到本地的“/用戶主目錄/.ssh”文件夾裏;
[email protected]'spassword:

#並要求輸入服務器上tel用戶的密碼;

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

6
、基於密鑰的客戶端登陸:
、創建用戶用於SSH登陸:
[root@lwh~]#useraddsshuser
[root@lwh~]#passwdsshuser
、在客戶端生成公鑰和私鑰對:
[root@lwh~]#su-sshuser//
切換用戶;
[sshuser@lwh~]$pwd//
用戶當前路徑;
/home/sshuser
[sshuser@lwh~]$ssh-keygen-trsa//
生成公鑰和私鑰對;
Generatingpublic/privatersakeypair.
Enterfileinwhichtosavethekey(/home/sshuser/.ssh/id_rsa):
Createddirectory'/home/sshuser/.ssh'.
Enterpassphrase(emptyfornopassphrase):(空,不需要密碼)
Entersamepassphraseagain:
Youridentificationhasbeensavedin/home/sshuser/.ssh/id_rsa.
Yourpublickeyhasbeensavedin/home/sshuser/.ssh/id_rsa.pub.
Thekeyfingerprintis:
0c:8d:9e:99:b5:95:32:70:96:6e:1c:38:71:57:4d:cb
[sshuser@lwh~]$ll.ssh///
查看生成的密鑰文件;
總用量16
-rw-------1sshusersshuser8832
517:22id_rsa
-rw-r--r--1sshusersshuser2252
517:22id_rsa.pub
、將生成的公鑰“id_rsa.pub”複製並改名添加到SSH服務器“/想要登陸的賬號/.ssh/authorized_keys”
//
SSH服務器相應的目錄下新建“.ssh”目錄:
[root@www~]#mkdir/sshuser/.ssh/
//
SSH客戶端,用scp命令進行復制:
[sshuser@lwh~]$
scp~/.ssh/[email protected]:~/.ssh/authorized_keys//注意登陸的用戶名,拷貝到那個宿主目錄下,就在客戶端以哪個賬號登陸;
Theauthenticityofhost'192.168.100.2(192.168.100.2)'can'tbeestablished.
RSAkeyfingerprintisfe:88:0f:f6:ac:d4:76:9a:ef:4b:16:28:37:36:ec:93.
Areyousureyouwanttocontinueconnecting(yes/no)?yes
Warning:Permanentlyadded'192.168.100.2'(RSA)tothelistofknownhosts.
[email protected]'spassword:
id_rsa.pub100%2250.2KB/s00:00
、在客戶端登陸:
[sshuser@lwh~][email protected]
Lastlogin:ThuFeb517:17:492009fromlinserv//
並沒有提示要輸入密碼;

7、其他設置:
//
不允許以root賬號登陸服務器在服務器端:
[root@www~]#vi/etc/ssh/sshd_config
PermitRootLoginno#
在配置文件中加入;
[root@www~]#servicesshdrestart

ssh[user@]hostname[command]
[user@]
:遠程計算機的用戶名
[command]
:連接成功後直接執行的命令
有時在無通過ssh連接到服務器時,可將客戶端~/.ssh裏面內容刪除後再試。

scp[user@]host:/path[-rpC]
文件在ssh客戶端與服務器端之間複製
-r
:遞歸
-p
:保留原文件權限
-C
:傳輸中壓縮數據




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章