免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1070 | 回复: 0
打印 上一主题 下一主题

SSH - Getting known_hosts to work [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-07 09:44 |只看该作者 |倒序浏览

                                Getting known_hosts to work
Logging in without a passwd in Linux
Open up your shell.
% ssh-keygen -t rsa
Just hit enter for the passphrase (that kind of defeats the purpose
of what we're doing). The default is to put the file it makes in your
$HOME directory. (echo $HOME). For this example, I'm assuming that's
what you did.
If it didn't exist already, this will have created a directory called .ssh in your home directory and created 2 files inside it:
-rw-------   1 myuser  myuser   1671 May 24  2007 id_rsa
-rw-r--r--   1 myuser  myuser    400 May 24  2007 id_rsa.pub
You need to copy the contents of the id_rsa.pub to your clipboard.
% cat id_rsa.pub
Copy it. It should looks something like this (not my actual key, of course)
ssh-rsa kjakjhasdhjfjkahsgdfhjkgasdjkhgfajkshdgfhjags834yg
swdhjgfjkashgdfjkhasgdfjkhgasdjkhfgasjkhdgfjkhasgdfjkhgasdjk
fhgasdcvjhasgdfjhkqg34jhkqgwejkhfgaskjhdgfkjhasgdfkjhagsd== myuser@Zap.local
Now ssh to the machine you want to log in to automatically.
% ssh 123.45.67.8
Enter your password as normal. Once logged in, let's check to see if you have an ssh directory.
% ls -la
If you see .ssh, cd into it. Otherwise mkdir .ssh and cd into it.
Now we just need to add your key to your authorized_hosts file. This
next command will either add to what you have already or create it if
it doesn't exist.
% cat authorized_hosts
Now paste the key you copied above. Hit enter to get to a new line and then Ctrl-D to stop editing.
To make sure that there aren't any issues with permissions, make sure that only this user can read the file.
% chmod 600 authorized_hosts
Now let's make sure that this directory has similar permissions. Go back up a directory and fix the permissions
% cd ../
% chmod 700 .ssh
That should do it. Try opening up a new shell window and log in.
% ssh 123.45.67.8
That should get you in without having to enter a password.
Extra credit: I think it's helpful to make sure you have hosts
mapped in your /etc/hosts file (Mac / Linux) if the IP or host you're
using doesn't have a convenient name for you. Windows XP users, this is
conveniently located in your c:\Windows\system32\drivers\etc\hosts
file. Of course, other systems vary.
In that file, just make an entry like this
123.45.67.8          server5
And save it. On a Linux system you may need to restart the network to have it take effect.
% /etc/rc.d/init.d/network restart
Now you can just ssh to the name
% ssh server5
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/83596/showart_1778983.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP