All things are difficult before they are easy. 没有软件的裸机是一具僵尸,没有硬件的软件是一个幽灵。2012,专注于Linux和C语言,关注自动化、性能测试,关注开源社区和开源测试工具、方法,尝试测试团队管理!

ssh配置及实现ssh免登陆Linux

上一篇 / 下一篇  2010-02-20 20:58:55 / 个人分类:Linux

去年4、5月份时,实现了ssh免登陆的,不过前几天又因工作再需要,重新做了一遍,因为以前做过的都记不得了,免不了google解决,现在总结一下。
1. ssh是什么?
Secure Shell or SSH is a network protocol that allows data to be exchanged using a secure channel between two networked devices. Used primarily on GNU/Linux and Unix based systems to access shell accounts, SSH was designed as a replacement for Telnet and other insecure remote shells, which send information, notably passwords, in plaintext, rendering them susceptible to packet analyzation.The encryption used by SSH provides confidentiality and integrity of data over an insecure network, such as the Internet.   -- from wikipedia
SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用SSH 协议可以有效防止远程管理过程中的信息泄露问题。
2. 准备工作
   假设A主机10.20.0.1想通过ssh登录到B主机10.20.0.2上。
   那么客户端(A主机)需要安装ssh客户端软件,服务器端(B主机开机sshd进程)需要安装ssh服务器软件。
   ssh客户端Linux发行版一般都自带的,对于ssh服务器端,Ubuntu用户可以sudo apt-get install openssh-server来安装,其他Linux用户也安装openssh-server即可。
   在各自的$HOME目录下都有一个.ssh隐藏目录。
3. 生成密钥
   在A主机,cd $HOME/.ssh
         运行命令ssh-keygen -t dsa 生成密钥。(dsa换成rsa,即是使用rsa加密算法生成密钥了)
         一路Enter键确认下来,当然遇到"yes/no?"一般选yes就好了。
4. 分发密钥(公钥)
   在A主机,scp ~/.ssh/id_dsa.pub  userB@10.20.0.2:~/.ssh/id_dsa.pub
   此过程中需要输入B主机的userB的密码。
   然后,在B主机:cat ~/.ssh/id_dsa.pub  >> ~/.ssh/authorized_keys (将id_dsa.pub的内容追加到 authorized_keys中)
5. 享受免登陆
   在A主机:ssh userB@10.20.0.2  不需输入密码即可登录B主机;
   当然 scp test userB@10.20.0.2 远程拷贝也不需输入密码了(scp基于ssh协议嘛);
   还可以ssh远程执行B主机上的命令或执行脚本,比如:
   ssh test userB@10.20.0.2 'apache2 -k start' #启动B主机上的Apache服务;
   远程执行多条命令可用分号隔开,如:ssh test userB@10.20.0.2 'ls;pwd'

参考文章
http://fanqiang.chinaunix.net/safe/program/2005-03-24/3012.shtml

TAG: Linux linux ssh 免登陆

 

评分:0

我来说两句

smile665

smile665

Stay hungry, stay foolish. 得意之时谨记,一半命运还掌握在上帝手里;失意之时须知,一半命运还掌握在自己手里。

日历

« 2024-04-19  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 955075
  • 日志数: 220
  • 建立时间: 2008-11-06
  • 更新时间: 2012-10-06

RSS订阅

Open Toolbar