ssh遠程登錄的過程
1.sshd啓動的時候會產生一個公鑰,每個小時更新一次公鑰
2.當客戶端收到服務端公鑰會版本協商(sshv1,sshv2)
3.版本協商完後,服務端會發公鑰(/etc/ssh/ssh_host_ras.pub給客戶端,這一步是沒加密
4.客戶端返回確認信息,把一個session_key通過公鑰加密發給服務端
# cat /etc/ssh/sshd_config |grep -v '#'|grep -v ^$
Port 22 --監聽端口
Protocol 2 --使用版本2
ListenAddress 0.0.0.0 --監聽地址
LoginGraceTime 2m --登錄超時時間
PermitRootLogin yes --允許root通過ssh登錄
MaxAuthTries 6 --密碼嘗試6次
RSAAuthentication yes --支持ras加密
PubkeyAuthentication yes --是否支持密鑰對驗證
AuthorizedKeysFile .ssh/authorized_keys --密鑰對驗證時,客服端公鑰存儲文件
PermitEmptyPasswords no --是否允許空密碼登錄
PasswordAuthentication yes --是否支持賬號/密碼登錄方式
UseDNS no --禁用DNS反解
Subsystem sftp /usr/libexec/openssh/sftp-server --支持sftp
AllowUsers root 只允許root 可以遠程
客戶端的命令:
# rpm -ql openssh-clients-4.3p2-36.el5|grep bin
/usr/bin/scp --支持遠程主機之間文件拷貝
scp -P 2222 /root/test.txt [email protected]:/tmp/test.txt
scp -P 2222 -r /root/ [email protected]:/tmp/test.txt
scp [email protected]:/etc/hosts /var/tmp --從0.254主機上下載一個文件
scp /etc/hosts [email protected]:/var/tmp --往0.254上傳一個文件
/usr/bin/sftp --sftp的客戶端
# /usr/bin/sftp -oport=2222 [email protected]
/usr/bin/ssh
# ssh -p 2222 [email protected]
/usr/bin/ssh-copy-id --拷貝公鑰至遠程主機對應的目錄
ssh驗證:
1.基於賬號/密碼的驗證
服務端:私鑰
客服端:公鑰
2.基於密鑰對的驗證
服務端:公鑰
客服端:私鑰
client(192.168.0.7)<-->server(192.168.0.29)
a. 在客戶端生成密鑰對
# 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): --給私鑰加密(123456)
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. --公鑰
ccess control configuration prevents your request from being
b. 拷貝公鑰至服務器,拷貝目標路徑:(你想用哪個用戶登錄就拷貝哪個用戶的家目錄$HOME/.ssh/authorized_keys)
第一種方法(手工拷貝):
在服務器上的操作:
#useradd kiki
# sudo -u kiki mkdir /home/kiki/.ssh
# sudo -u kiki chmod 700 /home/kiki/.ssh
在客戶端上上傳公鑰
# scp -P2222 /root/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys
1.sshd啓動的時候會產生一個公鑰,每個小時更新一次公鑰
2.當客戶端收到服務端公鑰會版本協商(sshv1,sshv2)
3.版本協商完後,服務端會發公鑰(/etc/ssh/ssh_host_ras.pub給客戶端,這一步是沒加密
4.客戶端返回確認信息,把一個session_key通過公鑰加密發給服務端
# cat /etc/ssh/sshd_config |grep -v '#'|grep -v ^$
Port 22 --監聽端口
Protocol 2 --使用版本2
ListenAddress 0.0.0.0 --監聽地址
LoginGraceTime 2m --登錄超時時間
PermitRootLogin yes --允許root通過ssh登錄
MaxAuthTries 6 --密碼嘗試6次
RSAAuthentication yes --支持ras加密
PubkeyAuthentication yes --是否支持密鑰對驗證
AuthorizedKeysFile .ssh/authorized_keys --密鑰對驗證時,客服端公鑰存儲文件
PermitEmptyPasswords no --是否允許空密碼登錄
PasswordAuthentication yes --是否支持賬號/密碼登錄方式
UseDNS no --禁用DNS反解
Subsystem sftp /usr/libexec/openssh/sftp-server --支持sftp
AllowUsers root 只允許root 可以遠程
客戶端的命令:
# rpm -ql openssh-clients-4.3p2-36.el5|grep bin
/usr/bin/scp --支持遠程主機之間文件拷貝
scp -P 2222 /root/test.txt [email protected]:/tmp/test.txt
scp -P 2222 -r /root/ [email protected]:/tmp/test.txt
scp [email protected]:/etc/hosts /var/tmp --從0.254主機上下載一個文件
scp /etc/hosts [email protected]:/var/tmp --往0.254上傳一個文件
/usr/bin/sftp --sftp的客戶端
# /usr/bin/sftp -oport=2222 [email protected]
/usr/bin/ssh
# ssh -p 2222 [email protected]
/usr/bin/ssh-copy-id --拷貝公鑰至遠程主機對應的目錄
ssh驗證:
1.基於賬號/密碼的驗證
服務端:私鑰
客服端:公鑰
2.基於密鑰對的驗證
服務端:公鑰
客服端:私鑰
client(192.168.0.7)<-->server(192.168.0.29)
a. 在客戶端生成密鑰對
# 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): --給私鑰加密(123456)
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. --公鑰
ccess control configuration prevents your request from being
b. 拷貝公鑰至服務器,拷貝目標路徑:(你想用哪個用戶登錄就拷貝哪個用戶的家目錄$HOME/.ssh/authorized_keys)
第一種方法(手工拷貝):
在服務器上的操作:
#useradd kiki
# sudo -u kiki mkdir /home/kiki/.ssh
# sudo -u kiki chmod 700 /home/kiki/.ssh
在客戶端上上傳公鑰
# scp -P2222 /root/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys