Chinaunix首页 | 论坛 | 博客
  • 博客访问: 762362
  • 博文数量: 790
  • 博客积分: 40560
  • 博客等级: 大将
  • 技术积分: 5065
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-28 16:29
文章分类

全部博文(790)

文章存档

2011年(1)

2008年(789)

我的朋友

分类: LINUX

2008-08-28 17:15:08

 
一直在SecureCRT上使用密码和键盘交互方式登陆ssh,一直没试成功,今天无意在一篇文章里受了点启发,顺便就在前些天装的虚拟机上试成了。客户端用的SecureCRT5.5.1,服务端为openSUSE10.3上默认安装的OpenSSH_4.6p1。

首先配置SecureCRT上的RSA密钥,打开SecureCRT→QuickConnect→Authentiation→PublicKey→Properties→CreateIdentityFile,Key选择RSA;Passphrase可以不同于密码,任意的字符串即可;Keylengthin为加密长度,可为512到2048位,要是在linux上可配置4096;下一步为生成过程,需要不停在进度条附近晃动鼠标,选择在x:\%USERPROFILE%\ApplicationData\VanDyke下生成两个文件,并且格式为OpensshKeyformat,要是选默认的StandardPublicKeyandVanDykePrivateKey可能还需要格式转换或有兼容问题,公钥Identity.pub和私钥Identity。

然后在opensuse上要使用密钥方式登陆的的用户目录下建立.ssh目录,这里我偷懒直接运行ssh-keygen工具创建本机密钥会自动创建.ssh目录并设置合适目录权限。

lxuser@suse10:/etc/ssh>ssh-keygen
Generatingpublic/privatersakeypair.
Enterfileinwhichtosavethekey(/home/lxuser/.ssh/id_rsa):
Createddirectory''/home/lxuser/.ssh''.
Enterpassphrase(emptyfornopassphrase):
Entersamepassphraseagain:
Youridentificationhasbeensavedin/home/lxuser/.ssh/id_rsa.
Yourpublickeyhasbeensavedin/home/lxuser/.ssh/id_rsa.pub.
Thekeyfingerprintis:
d8:07:b9:d6:f9:4d:0c:e3:c7:8c:82:f4:a3:20:71:f4lxuser@suse10

利用sftp或其他方式将公钥Identity.pub上传到刚建立好的.ssh目录里,修改文件名为authorized_keys2,这是因为使用的是authorized_keys这个文件,而用的ssh版本为2(openSUSE默认也仅使用Protocol2).

lxuser@suse10:~/.ssh>mvIdentity.pubauthorized_keys2
为安全起见,修改该文件的访问权限,保证除属主外没人能修改
lxuser@suse10:~/.ssh>chmod600authorized_keys2
lxuser@suse10:~/.ssh>ll
总计?16
-rw-------1lxuserusers23411-0220:20authorized_keys2
-rw-------1lxuserusers174311-0219:23id_rsa
-rw-r--r--1lxuserusers39511-0219:23id_rsa.pub

再回到SecureCRT,在QuickConnect→Authentiation处仅勾选PublicKey,并设置属性Properties,指定Useidentityorcertificatefile为私钥Identity,确定后连接,正常的话会提示输入前面设置的Passphrase,若成功则直接登陆了。

Lastlogin:FriNov220:38:212007fromprinter.mshome.net
Havealotoffun...

至此任务算基本成功了。既然已经成功使用了ssh的RSA功能,那么索性让openssh只支持RSA验证,否则既支持普通密码又支持RSA就没什么意思了,根本没把安全提高。修改ssh_config配置文件

lxuser@suse10:/etc/ssh>vissh_config
取消密码登陆验证
PasswordAuthenticationno

然后重启sshd服务再次尝试用键盘和密码交互登陆,就提示不成功了,而使用PublicKey是方便了许多,免去了反复输入密码的麻烦,安全较高(不过要是客户端宿主机本身不安全,那后果也就......)。

suse10:/etc/ssh#vissh_config
suse10:/etc/ssh#rcsshdrestart
ShuttingdownSSHdaemondone
StartingSSHdaemondone

阅读(478) | 评论(0) | 转发(0) |
0

上一篇:linux 设置 sslexplorer

下一篇:linux 实现 cvs

给主人留下些什么吧!~~