SlideShare a Scribd company logo
1 of 10
1. SecureCRT 生成公钥/私钥对,“OpenSSH 密钥格式”, (puttygen.exe 也

可以生成密钥对)

a. 公钥上传到服务器,导入到/root/.ssh/authorized_keys2 文件中;

#cat ./Identify.pub >> /root/.ssh/authorized_keys2

b. 修改 sshd 的配置文件;

$ sudo vim /etc/ssh/sshd_config


Protocol 2 /仅允许使用 SSH2


PubkeyAuthentication yes /*启用 PublicKey 认证


AuthorizedKeysFile .ssh/authorized_keys2 /*PublicKey 文件路径


PasswordAuthentication no /*禁止密码验证登录


c. 重启 sshd 服务;


#service sshd restart


d. 测试;


使用 SecureCRT 登录,ok,没有问题;


将私钥文件 Identify 给一台 Linux 客户端,


#ssh -i Identify username@server


同样 ok,也没有问题;
提示:Linux 客户端中可能会出现提示说,private key file 未设保护;


只需要


#chmod 600 Identify




2. SecureCRT 生成公钥/私钥对,“标准公钥和 VanDyke 私钥格式”,


a. 公钥上传到服务器,格式转换后,导入到/root/.ssh/authorized_keys3 文件中;

# ssh-keygen -i -f /home/guoq/Identity2.pub >> /root/.ssh/authorized_keys3

b. 修改 sshd 的配置文件;

$ sudo vim /etc/ssh/sshd_config


Protocol 2 /仅允许使用 SSH2


PubkeyAuthentication yes /*启用 PublicKey 认证


AuthorizedKeysFile .ssh/authorized_keys3 /*PublicKey 文件路径


PasswordAuthentication no /*禁止密码验证登录


c. 重启 sshd 服务;


#service sshd restart


d. 测试;
在 SecureCRT 中建立另外一个 Session,登录同样的服务器,只是私钥文件选

用 Identify2;


退出,


使用 SecureCRT 的 Session 登录,失败,因为公钥/私钥已经改变;


使用 SecureCRT 的 Session2 登录,ok,没有问题;


将私钥文件 Identify2 给一台 Linux 客户端,


#ssh -i Identify2 username@server


输入三次 passphrase 后,失败。


使用 SecureCRT 将 Identify2 转换成为 OpenSSH 格式后,Linux 客户端重试,

ok,没有问题;




3. xshell 生成公钥私钥对,DSA, openSSH 格式,

a. 公钥上传到服务器,导入到/root/.ssh/authorized_keys4 文件中;

#cat /home/guoq/id_dsa_1024.pub >> /root/.ssh/authorized_keys4

b. 修改 sshd 的配置文件;

#vim /etc/ssh/sshd_config


Protocol 2 /仅允许使用 SSH2


PubkeyAuthentication yes /*启用 PublicKey 认证
AuthorizedKeysFile .ssh/authorized_keys4 /*PublicKey 文件路径


PasswordAuthentication no /*禁止密码验证登录


c. 重启 sshd 服务;


#service sshd restart


d. 测试;


使用 xshell 登录,ok,没有问题;


将私钥文件 id_dsa_1024 给一台 Linux 客户端,


#ssh -i id_dsa_1024 username@server


同样 ok,也没有问题;




4. 将 xshell 的私钥文件 id_dsa_1024 给 SecureCRT 使用;


也同样 ok,没有问题;




5. 刚才的步骤 3 中,导出的私钥格式,选择为 OpenSSH,这样步骤 4 就没有

问题了;
验证是否导出的私钥格式,选择为"User Key Files(*.pri)", 重复步骤 4,果然不

可以;


同样的,私钥格式,选择为"*.*", 重复步骤 4,也不可以;


Linux 安全配置,公钥/私钥方式

大概有如下几个方面:


1. 禁止 root 帐号 ssh,使用自定义帐号 ssh;


这样一来,黑客要先猜到帐号,然后才能猜解密码;


2. 禁止帐号登录,使用 pubkey 登录;


3. 作 ip ACL,只允许几个特定的 IP 访问;


4. ssh 端口迁移,将默认 22 端口改为其他端口;


5. 启动尽量少的服务;如无必要,不起服务。




但是测试 pubkey 的时候,发现了一个问题:使用 xshell 产生的私钥文件,拿到 securecrt 使用的时候,不


成功!


具体原因,请查看全文的最后一句结论。




问题 2:一台 Linux 机器如何使用私钥,ssh 另外一台 Linux?



命令格式如下:#ssh -i identity_file username@server




经过实验发现:xshell 产生的私钥文件,在 Linux 上面可以直接使用,没有问题;使用方法:
#ssh -i identity_file username@server

identity_file 为 xshell 产生的私钥文件;




经过搜索发现:SecureCRT 产生的私钥文件,在 Linux 上面也是可以使用的;


如果为“标准公钥和 VanDyke 私钥格式”,那么需要使用 ssh-keygen 转换一下,然后使用即可;


如果为“OpenSSH 密钥格式”,就无需转换,可以直接使用。




也就是说:xshell 可以与 Linux 共享私钥文件(private key file), SecureCRT 也可以于 Linux 共享私钥文件


(private key file), 为什么 xshell 与 SecureCRT 不可以共享私钥文件呢?




我们将整个过程梳理一遍;


1. SecureCRT 生成公钥/私钥对,“OpenSSH 密钥格式”,


a. 公钥上传到服务器,导入到/root/.ssh/authorized_keys2 文件中;

#cat ./Identify.pub >> /root/.ssh/authorized_keys2

b. 修改 sshd 的配置文件;

$ sudo vim /etc/ssh/sshd_config

Protocol 2 /仅允许使用 SSH2



PubkeyAuthentication yes /*启用 PublicKey 认证



AuthorizedKeysFile .ssh/authorized_keys2 /*PublicKey 文件路径



PasswordAuthentication no /*禁止密码验证登录



c. 重启 sshd 服务;



#service sshd restart


d. 测试;
使用 SecureCRT 登录,ok,没有问题;



将私钥文件 Identify 给一台 Linux 客户端,



#ssh -i Identify username@server


同样 ok,也没有问题;



提示:Linux 客户端中可能会出现提示说,private key file 未设保护;



只需要



#chmod 600 Identify




2. SecureCRT 生成公钥/私钥对,“标准公钥和 VanDyke 私钥格式”,



a. 公钥上传到服务器,格式转换后,导入到/root/.ssh/authorized_keys3 文件中;


# ssh-keygen -i -f /home/guoq/Identity2.pub >> /root/.ssh/authorized_keys3

b. 修改 sshd 的配置文件;


$ sudo vim /etc/ssh/sshd_config


Protocol 2 /仅允许使用 SSH2



PubkeyAuthentication yes /*启用 PublicKey 认证



AuthorizedKeysFile .ssh/authorized_keys3 /*PublicKey 文件路径



PasswordAuthentication no /*禁止密码验证登录



c. 重启 sshd 服务;
#service sshd restart


d. 测试;



在 SecureCRT 中建立另外一个 Session,登录同样的服务器,只是私钥文件选用 Identify2;



退出,



使用 SecureCRT 的 Session 登录,失败,因为公钥/私钥已经改变;



使用 SecureCRT 的 Session2 登录,ok,没有问题;



将私钥文件 Identify2 给一台 Linux 客户端,



#ssh -i Identify2 username@server


输入三次 passphrase 后,失败。



使用 SecureCRT 将 Identify2 转换成为 OpenSSH 格式后,Linux 客户端重试,ok,没有问题;




3. xshell 生成公钥私钥对,DSA, openSSH 格式,


a. 公钥上传到服务器,导入到/root/.ssh/authorized_keys4 文件中;

#cat /home/guoq/id_dsa_1024.pub >> /root/.ssh/authorized_keys4

b. 修改 sshd 的配置文件;

#vim /etc/ssh/sshd_config

Protocol 2 /仅允许使用 SSH2



PubkeyAuthentication yes /*启用 PublicKey 认证



AuthorizedKeysFile .ssh/authorized_keys4 /*PublicKey 文件路径
PasswordAuthentication no /*禁止密码验证登录



c. 重启 sshd 服务;



#service sshd restart


d. 测试;



使用 xshell 登录,ok,没有问题;



将私钥文件 id_dsa_1024 给一台 Linux 客户端,



#ssh -i id_dsa_1024 username@server


同样 ok,也没有问题;




4. 将 xshell 的私钥文件 id_dsa_1024 给 SecureCRT 使用;



也同样 ok,没有问题;




5. 刚才的步骤 3 中,导出的私钥格式,选择为 OpenSSH,这样步骤 4 就没有问题了;



验证是否导出的私钥格式,选择为"User Key Files(*.pri)", 重复步骤 4,果然不可以;



同样的,私钥格式,选择为"*.*", 重复步骤 4,也不可以;




so. 结论是,如果是 OpenSSH 格式的私钥文件,那么 xshell, SecureCRT, Linux 客户端均可以使用。
Linux安全配置,公钥/私钥方式

More Related Content

What's hot

unethost.com - ssh使用手冊
unethost.com - ssh使用手冊unethost.com - ssh使用手冊
unethost.com - ssh使用手冊unethost.com
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡cachowu
 
lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用hugo
 
Nae client(using Node.js to create shell cmd)
Nae client(using Node.js to create shell cmd)Nae client(using Node.js to create shell cmd)
Nae client(using Node.js to create shell cmd)fisher zheng
 
Perl在nginx里的应用
Perl在nginx里的应用Perl在nginx里的应用
Perl在nginx里的应用琛琳 饶
 
工作站教學
工作站教學工作站教學
工作站教學丕祐 陳
 
nodejs在微博前端开发中的应用
nodejs在微博前端开发中的应用nodejs在微博前端开发中的应用
nodejs在微博前端开发中的应用dong yuwei
 
为什么上网浏览要用Shadowsocks?
为什么上网浏览要用Shadowsocks?为什么上网浏览要用Shadowsocks?
为什么上网浏览要用Shadowsocks?zzzzzz gg
 
为10g rac cluster添加节点
为10g rac cluster添加节点为10g rac cluster添加节点
为10g rac cluster添加节点maclean liu
 
使用Nginx轻松实现开源负载均衡——对外版
使用Nginx轻松实现开源负载均衡——对外版使用Nginx轻松实现开源负载均衡——对外版
使用Nginx轻松实现开源负载均衡——对外版pigso
 
Amazon EC2 免費教學:使用 User Data 在 EC2 Instance 上建一個簡單的網站
Amazon EC2 免費教學:使用 User Data 在 EC2 Instance 上建一個簡單的網站Amazon EC2 免費教學:使用 User Data 在 EC2 Instance 上建一個簡單的網站
Amazon EC2 免費教學:使用 User Data 在 EC2 Instance 上建一個簡單的網站April Yang
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡Cary Yang
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡guest2d0fe3
 
中纺科技安装实施文档
中纺科技安装实施文档中纺科技安装实施文档
中纺科技安装实施文档liangsuilong
 

What's hot (14)

unethost.com - ssh使用手冊
unethost.com - ssh使用手冊unethost.com - ssh使用手冊
unethost.com - ssh使用手冊
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡
 
lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用
 
Nae client(using Node.js to create shell cmd)
Nae client(using Node.js to create shell cmd)Nae client(using Node.js to create shell cmd)
Nae client(using Node.js to create shell cmd)
 
Perl在nginx里的应用
Perl在nginx里的应用Perl在nginx里的应用
Perl在nginx里的应用
 
工作站教學
工作站教學工作站教學
工作站教學
 
nodejs在微博前端开发中的应用
nodejs在微博前端开发中的应用nodejs在微博前端开发中的应用
nodejs在微博前端开发中的应用
 
为什么上网浏览要用Shadowsocks?
为什么上网浏览要用Shadowsocks?为什么上网浏览要用Shadowsocks?
为什么上网浏览要用Shadowsocks?
 
为10g rac cluster添加节点
为10g rac cluster添加节点为10g rac cluster添加节点
为10g rac cluster添加节点
 
使用Nginx轻松实现开源负载均衡——对外版
使用Nginx轻松实现开源负载均衡——对外版使用Nginx轻松实现开源负载均衡——对外版
使用Nginx轻松实现开源负载均衡——对外版
 
Amazon EC2 免費教學:使用 User Data 在 EC2 Instance 上建一個簡單的網站
Amazon EC2 免費教學:使用 User Data 在 EC2 Instance 上建一個簡單的網站Amazon EC2 免費教學:使用 User Data 在 EC2 Instance 上建一個簡單的網站
Amazon EC2 免費教學:使用 User Data 在 EC2 Instance 上建一個簡單的網站
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡
 
中纺科技安装实施文档
中纺科技安装实施文档中纺科技安装实施文档
中纺科技安装实施文档
 

Viewers also liked

FD Magazine - Consolidatie bij Jan De Nul Group - April 2013
FD Magazine - Consolidatie bij Jan De Nul Group - April 2013FD Magazine - Consolidatie bij Jan De Nul Group - April 2013
FD Magazine - Consolidatie bij Jan De Nul Group - April 2013Martin van Wunnik
 
richard paulino problem set
richard paulino problem setrichard paulino problem set
richard paulino problem setRichard Paulino
 
Copy (22) of perf scenarios
Copy (22) of perf scenariosCopy (22) of perf scenarios
Copy (22) of perf scenariosdsfssk542
 
Certificacion a grado 2012-II TSU GSDL
Certificacion a grado 2012-II TSU GSDLCertificacion a grado 2012-II TSU GSDL
Certificacion a grado 2012-II TSU GSDLDavid Leon Sicilia
 
Regimento - UENP
Regimento - UENPRegimento - UENP
Regimento - UENPdaomuenp
 
Aina sellarès i marta casao 2n b
Aina sellarès i marta casao 2n bAina sellarès i marta casao 2n b
Aina sellarès i marta casao 2n bdretsjoanoro
 
Impressions about the mobility in Turkey by Romanian students 2012
Impressions about the mobility in Turkey by Romanian students 2012Impressions about the mobility in Turkey by Romanian students 2012
Impressions about the mobility in Turkey by Romanian students 2012Mariana Radulescu
 
Niño juan pablo
Niño juan pabloNiño juan pablo
Niño juan pabloNijupa
 
SMCS Presentation
SMCS PresentationSMCS Presentation
SMCS PresentationWalkerTay
 
How to "Use" your Users
How to "Use" your UsersHow to "Use" your Users
How to "Use" your UsersVinnie Lauria
 
Quentry—Beyond Image Sharing Brochure
Quentry—Beyond Image Sharing BrochureQuentry—Beyond Image Sharing Brochure
Quentry—Beyond Image Sharing BrochureBrainlab
 
Reliable security in cloud computing environment 2-3-4-5-6
Reliable security in cloud computing environment 2-3-4-5-6Reliable security in cloud computing environment 2-3-4-5-6
Reliable security in cloud computing environment 2-3-4-5-6IAEME Publication
 
Copyright crashcourse coram(2)6340.64
Copyright crashcourse coram(2)6340.64Copyright crashcourse coram(2)6340.64
Copyright crashcourse coram(2)6340.64Cora Mendez
 
Embauche Fonctionnaires
Embauche FonctionnairesEmbauche Fonctionnaires
Embauche Fonctionnairesmimimarigny
 
Tiny and smart - A propos d'humain dans les organisations
Tiny and smart - A propos d'humain dans les organisationsTiny and smart - A propos d'humain dans les organisations
Tiny and smart - A propos d'humain dans les organisationsPatrick Ostertag
 
Instructivo i 2011 - especial
Instructivo i 2011 - especialInstructivo i 2011 - especial
Instructivo i 2011 - especialDrès Hernández
 
moragoprl !!! 2008 Sevilla - Visita turistica !!!
moragoprl !!! 2008 Sevilla - Visita turistica !!!moragoprl !!! 2008 Sevilla - Visita turistica !!!
moragoprl !!! 2008 Sevilla - Visita turistica !!!Pedro Rodriguez
 

Viewers also liked (20)

Scaling and sustaining change
Scaling and sustaining changeScaling and sustaining change
Scaling and sustaining change
 
FD Magazine - Consolidatie bij Jan De Nul Group - April 2013
FD Magazine - Consolidatie bij Jan De Nul Group - April 2013FD Magazine - Consolidatie bij Jan De Nul Group - April 2013
FD Magazine - Consolidatie bij Jan De Nul Group - April 2013
 
Heinzman recommendation
Heinzman recommendationHeinzman recommendation
Heinzman recommendation
 
richard paulino problem set
richard paulino problem setrichard paulino problem set
richard paulino problem set
 
Copy (22) of perf scenarios
Copy (22) of perf scenariosCopy (22) of perf scenarios
Copy (22) of perf scenarios
 
Certificacion a grado 2012-II TSU GSDL
Certificacion a grado 2012-II TSU GSDLCertificacion a grado 2012-II TSU GSDL
Certificacion a grado 2012-II TSU GSDL
 
Regimento - UENP
Regimento - UENPRegimento - UENP
Regimento - UENP
 
Aina sellarès i marta casao 2n b
Aina sellarès i marta casao 2n bAina sellarès i marta casao 2n b
Aina sellarès i marta casao 2n b
 
Яндекс-книга
Яндекс-книгаЯндекс-книга
Яндекс-книга
 
Impressions about the mobility in Turkey by Romanian students 2012
Impressions about the mobility in Turkey by Romanian students 2012Impressions about the mobility in Turkey by Romanian students 2012
Impressions about the mobility in Turkey by Romanian students 2012
 
Niño juan pablo
Niño juan pabloNiño juan pablo
Niño juan pablo
 
SMCS Presentation
SMCS PresentationSMCS Presentation
SMCS Presentation
 
How to "Use" your Users
How to "Use" your UsersHow to "Use" your Users
How to "Use" your Users
 
Quentry—Beyond Image Sharing Brochure
Quentry—Beyond Image Sharing BrochureQuentry—Beyond Image Sharing Brochure
Quentry—Beyond Image Sharing Brochure
 
Reliable security in cloud computing environment 2-3-4-5-6
Reliable security in cloud computing environment 2-3-4-5-6Reliable security in cloud computing environment 2-3-4-5-6
Reliable security in cloud computing environment 2-3-4-5-6
 
Copyright crashcourse coram(2)6340.64
Copyright crashcourse coram(2)6340.64Copyright crashcourse coram(2)6340.64
Copyright crashcourse coram(2)6340.64
 
Embauche Fonctionnaires
Embauche FonctionnairesEmbauche Fonctionnaires
Embauche Fonctionnaires
 
Tiny and smart - A propos d'humain dans les organisations
Tiny and smart - A propos d'humain dans les organisationsTiny and smart - A propos d'humain dans les organisations
Tiny and smart - A propos d'humain dans les organisations
 
Instructivo i 2011 - especial
Instructivo i 2011 - especialInstructivo i 2011 - especial
Instructivo i 2011 - especial
 
moragoprl !!! 2008 Sevilla - Visita turistica !!!
moragoprl !!! 2008 Sevilla - Visita turistica !!!moragoprl !!! 2008 Sevilla - Visita turistica !!!
moragoprl !!! 2008 Sevilla - Visita turistica !!!
 

Similar to Linux安全配置,公钥/私钥方式

資訊安全筆記 2023_0129_0205.docx
資訊安全筆記 2023_0129_0205.docx資訊安全筆記 2023_0129_0205.docx
資訊安全筆記 2023_0129_0205.docxssuser9026c8
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结Yiwei Ma
 
Puppet安装测试
Puppet安装测试Puppet安装测试
Puppet安装测试Yiwei Ma
 
Cent os 安装 subversion
Cent os 安装 subversionCent os 安装 subversion
Cent os 安装 subversionYUCHENG HU
 
Centos下安装apache + subversion
Centos下安装apache + subversionCentos下安装apache + subversion
Centos下安装apache + subversionYiwei Ma
 
應用程式部署
應用程式部署應用程式部署
應用程式部署Shengyou Fan
 
.NET Security Application/Web Development - Part III
.NET Security Application/Web Development - Part III.NET Security Application/Web Development - Part III
.NET Security Application/Web Development - Part IIIChen-Tien Tsai
 
Helix安装说明
Helix安装说明Helix安装说明
Helix安装说明Yiwei Ma
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuMarsZ Chen
 
AWS EC2 for beginner
AWS EC2 for beginnerAWS EC2 for beginner
AWS EC2 for beginnerazole Lai
 
GNU Build System
GNU Build SystemGNU Build System
GNU Build Systemimacat .
 
Windows Password
Windows PasswordWindows Password
Windows Passwordyeahlost
 
6kbbs vulnerability report
6kbbs vulnerability report6kbbs vulnerability report
6kbbs vulnerability reportinsight-labs
 

Similar to Linux安全配置,公钥/私钥方式 (14)

資訊安全筆記 2023_0129_0205.docx
資訊安全筆記 2023_0129_0205.docx資訊安全筆記 2023_0129_0205.docx
資訊安全筆記 2023_0129_0205.docx
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结
 
Puppet安装测试
Puppet安装测试Puppet安装测试
Puppet安装测试
 
Cent os 安装 subversion
Cent os 安装 subversionCent os 安装 subversion
Cent os 安装 subversion
 
憑證
憑證憑證
憑證
 
Centos下安装apache + subversion
Centos下安装apache + subversionCentos下安装apache + subversion
Centos下安装apache + subversion
 
應用程式部署
應用程式部署應用程式部署
應用程式部署
 
.NET Security Application/Web Development - Part III
.NET Security Application/Web Development - Part III.NET Security Application/Web Development - Part III
.NET Security Application/Web Development - Part III
 
Helix安装说明
Helix安装说明Helix安装说明
Helix安装说明
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for Ubuntu
 
AWS EC2 for beginner
AWS EC2 for beginnerAWS EC2 for beginner
AWS EC2 for beginner
 
GNU Build System
GNU Build SystemGNU Build System
GNU Build System
 
Windows Password
Windows PasswordWindows Password
Windows Password
 
6kbbs vulnerability report
6kbbs vulnerability report6kbbs vulnerability report
6kbbs vulnerability report
 

Linux安全配置,公钥/私钥方式

  • 1. 1. SecureCRT 生成公钥/私钥对,“OpenSSH 密钥格式”, (puttygen.exe 也 可以生成密钥对) a. 公钥上传到服务器,导入到/root/.ssh/authorized_keys2 文件中; #cat ./Identify.pub >> /root/.ssh/authorized_keys2 b. 修改 sshd 的配置文件; $ sudo vim /etc/ssh/sshd_config Protocol 2 /仅允许使用 SSH2 PubkeyAuthentication yes /*启用 PublicKey 认证 AuthorizedKeysFile .ssh/authorized_keys2 /*PublicKey 文件路径 PasswordAuthentication no /*禁止密码验证登录 c. 重启 sshd 服务; #service sshd restart d. 测试; 使用 SecureCRT 登录,ok,没有问题; 将私钥文件 Identify 给一台 Linux 客户端, #ssh -i Identify username@server 同样 ok,也没有问题;
  • 2. 提示:Linux 客户端中可能会出现提示说,private key file 未设保护; 只需要 #chmod 600 Identify 2. SecureCRT 生成公钥/私钥对,“标准公钥和 VanDyke 私钥格式”, a. 公钥上传到服务器,格式转换后,导入到/root/.ssh/authorized_keys3 文件中; # ssh-keygen -i -f /home/guoq/Identity2.pub >> /root/.ssh/authorized_keys3 b. 修改 sshd 的配置文件; $ sudo vim /etc/ssh/sshd_config Protocol 2 /仅允许使用 SSH2 PubkeyAuthentication yes /*启用 PublicKey 认证 AuthorizedKeysFile .ssh/authorized_keys3 /*PublicKey 文件路径 PasswordAuthentication no /*禁止密码验证登录 c. 重启 sshd 服务; #service sshd restart d. 测试;
  • 3. 在 SecureCRT 中建立另外一个 Session,登录同样的服务器,只是私钥文件选 用 Identify2; 退出, 使用 SecureCRT 的 Session 登录,失败,因为公钥/私钥已经改变; 使用 SecureCRT 的 Session2 登录,ok,没有问题; 将私钥文件 Identify2 给一台 Linux 客户端, #ssh -i Identify2 username@server 输入三次 passphrase 后,失败。 使用 SecureCRT 将 Identify2 转换成为 OpenSSH 格式后,Linux 客户端重试, ok,没有问题; 3. xshell 生成公钥私钥对,DSA, openSSH 格式, a. 公钥上传到服务器,导入到/root/.ssh/authorized_keys4 文件中; #cat /home/guoq/id_dsa_1024.pub >> /root/.ssh/authorized_keys4 b. 修改 sshd 的配置文件; #vim /etc/ssh/sshd_config Protocol 2 /仅允许使用 SSH2 PubkeyAuthentication yes /*启用 PublicKey 认证
  • 4. AuthorizedKeysFile .ssh/authorized_keys4 /*PublicKey 文件路径 PasswordAuthentication no /*禁止密码验证登录 c. 重启 sshd 服务; #service sshd restart d. 测试; 使用 xshell 登录,ok,没有问题; 将私钥文件 id_dsa_1024 给一台 Linux 客户端, #ssh -i id_dsa_1024 username@server 同样 ok,也没有问题; 4. 将 xshell 的私钥文件 id_dsa_1024 给 SecureCRT 使用; 也同样 ok,没有问题; 5. 刚才的步骤 3 中,导出的私钥格式,选择为 OpenSSH,这样步骤 4 就没有 问题了;
  • 5. 验证是否导出的私钥格式,选择为"User Key Files(*.pri)", 重复步骤 4,果然不 可以; 同样的,私钥格式,选择为"*.*", 重复步骤 4,也不可以; Linux 安全配置,公钥/私钥方式 大概有如下几个方面: 1. 禁止 root 帐号 ssh,使用自定义帐号 ssh; 这样一来,黑客要先猜到帐号,然后才能猜解密码; 2. 禁止帐号登录,使用 pubkey 登录; 3. 作 ip ACL,只允许几个特定的 IP 访问; 4. ssh 端口迁移,将默认 22 端口改为其他端口; 5. 启动尽量少的服务;如无必要,不起服务。 但是测试 pubkey 的时候,发现了一个问题:使用 xshell 产生的私钥文件,拿到 securecrt 使用的时候,不 成功! 具体原因,请查看全文的最后一句结论。 问题 2:一台 Linux 机器如何使用私钥,ssh 另外一台 Linux? 命令格式如下:#ssh -i identity_file username@server 经过实验发现:xshell 产生的私钥文件,在 Linux 上面可以直接使用,没有问题;使用方法:
  • 6. #ssh -i identity_file username@server identity_file 为 xshell 产生的私钥文件; 经过搜索发现:SecureCRT 产生的私钥文件,在 Linux 上面也是可以使用的; 如果为“标准公钥和 VanDyke 私钥格式”,那么需要使用 ssh-keygen 转换一下,然后使用即可; 如果为“OpenSSH 密钥格式”,就无需转换,可以直接使用。 也就是说:xshell 可以与 Linux 共享私钥文件(private key file), SecureCRT 也可以于 Linux 共享私钥文件 (private key file), 为什么 xshell 与 SecureCRT 不可以共享私钥文件呢? 我们将整个过程梳理一遍; 1. SecureCRT 生成公钥/私钥对,“OpenSSH 密钥格式”, a. 公钥上传到服务器,导入到/root/.ssh/authorized_keys2 文件中; #cat ./Identify.pub >> /root/.ssh/authorized_keys2 b. 修改 sshd 的配置文件; $ sudo vim /etc/ssh/sshd_config Protocol 2 /仅允许使用 SSH2 PubkeyAuthentication yes /*启用 PublicKey 认证 AuthorizedKeysFile .ssh/authorized_keys2 /*PublicKey 文件路径 PasswordAuthentication no /*禁止密码验证登录 c. 重启 sshd 服务; #service sshd restart d. 测试;
  • 7. 使用 SecureCRT 登录,ok,没有问题; 将私钥文件 Identify 给一台 Linux 客户端, #ssh -i Identify username@server 同样 ok,也没有问题; 提示:Linux 客户端中可能会出现提示说,private key file 未设保护; 只需要 #chmod 600 Identify 2. SecureCRT 生成公钥/私钥对,“标准公钥和 VanDyke 私钥格式”, a. 公钥上传到服务器,格式转换后,导入到/root/.ssh/authorized_keys3 文件中; # ssh-keygen -i -f /home/guoq/Identity2.pub >> /root/.ssh/authorized_keys3 b. 修改 sshd 的配置文件; $ sudo vim /etc/ssh/sshd_config Protocol 2 /仅允许使用 SSH2 PubkeyAuthentication yes /*启用 PublicKey 认证 AuthorizedKeysFile .ssh/authorized_keys3 /*PublicKey 文件路径 PasswordAuthentication no /*禁止密码验证登录 c. 重启 sshd 服务;
  • 8. #service sshd restart d. 测试; 在 SecureCRT 中建立另外一个 Session,登录同样的服务器,只是私钥文件选用 Identify2; 退出, 使用 SecureCRT 的 Session 登录,失败,因为公钥/私钥已经改变; 使用 SecureCRT 的 Session2 登录,ok,没有问题; 将私钥文件 Identify2 给一台 Linux 客户端, #ssh -i Identify2 username@server 输入三次 passphrase 后,失败。 使用 SecureCRT 将 Identify2 转换成为 OpenSSH 格式后,Linux 客户端重试,ok,没有问题; 3. xshell 生成公钥私钥对,DSA, openSSH 格式, a. 公钥上传到服务器,导入到/root/.ssh/authorized_keys4 文件中; #cat /home/guoq/id_dsa_1024.pub >> /root/.ssh/authorized_keys4 b. 修改 sshd 的配置文件; #vim /etc/ssh/sshd_config Protocol 2 /仅允许使用 SSH2 PubkeyAuthentication yes /*启用 PublicKey 认证 AuthorizedKeysFile .ssh/authorized_keys4 /*PublicKey 文件路径
  • 9. PasswordAuthentication no /*禁止密码验证登录 c. 重启 sshd 服务; #service sshd restart d. 测试; 使用 xshell 登录,ok,没有问题; 将私钥文件 id_dsa_1024 给一台 Linux 客户端, #ssh -i id_dsa_1024 username@server 同样 ok,也没有问题; 4. 将 xshell 的私钥文件 id_dsa_1024 给 SecureCRT 使用; 也同样 ok,没有问题; 5. 刚才的步骤 3 中,导出的私钥格式,选择为 OpenSSH,这样步骤 4 就没有问题了; 验证是否导出的私钥格式,选择为"User Key Files(*.pri)", 重复步骤 4,果然不可以; 同样的,私钥格式,选择为"*.*", 重复步骤 4,也不可以; so. 结论是,如果是 OpenSSH 格式的私钥文件,那么 xshell, SecureCRT, Linux 客户端均可以使用。