linux-祕鑰生成

服務器sshd配置
#vim /etc/ssh/sshd_conf
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

#/etc/init.d/sshd restart

windows生成密鑰

Xshell

打開Xshell->工具->新建用戶密鑰生成嚮導(W)

RSA加密方式,2048位密鑰長度->輸入公鑰名稱(wangs_rsa),密鑰密碼,下一步

公鑰格式(ssh2-openssh)->保存文件,將公鑰保存到本地->完成

這是會彈出會話框,裏面有你剛剛生成的私鑰(與密鑰名稱相同),選中私鑰,點擊導出,將私鑰導出到本地

如今,本地就有一對對應公鑰和私鑰了(wangs_rsa和wangs_rsa.pub)


windows下登陸
xshell登陸

將公鑰id_rsa.pub上傳到目標服務器用戶下.ssh目錄

若是沒有能夠新建,注意權限
#mkdir .ssh
#chmod 700 .ssh
#cat id_rsa.pub >> authorized_keys
#chmod 600 authorized_keys
新建登陸,輸入用戶名後,SSH身份驗證時選擇public key,選擇剛剛生成的私鑰,若是私鑰設置密碼,輸入密碼,不然可便可登陸




linux 密鑰生成

#ssh-keygen -t rsa

一路回車,根據提示,能夠設置名稱添加密碼等,最後生成一對私鑰和公鑰


linux登陸

方法1:

在密鑰生成的機器上

# ssh-copy-id -i /root/.ssh/id_rsa.pub  root@218.111.89.222

#sshroot@218.111.89.222

方法2:

將公鑰id_rsa.pub上傳到目標服務器用戶下.ssh目錄

若是沒有能夠新建,注意權限
#mkdir .ssh
#chmod 700 .ssh
#cat id_rsa.pub >> authorized_keys
#chmod 600 authorized_keys

#ssh root@218.111.89.222

注意
私鑰通常在.ssh下,權限爲700


若是沒法登陸,參照以下命令
# ssh-agent bash --login -i
# ssh-add id_rsa

PS:

首次進行ssh連接時,出現如下提示:

The authenticity of host '58.221.186.137 (58.221.186.137)' can't be established.  RSA key fingerprint is a0:00:d3:33:54:96:40:03:ff:ad:15:a9:59:22:f4:2a. 
Are you sure you want to continue connecting (yes/no)?  

修改文件:

#vim /etc/ssh/ssh_config
修改以下

StrictHostKeyChecking no
相關文章
相關標籤/搜索