无密码访问ssh
2015-07-01 17:34
232 查看
最近一个项目用的是linux,测试/生产/内/外网服务器就有10台左右,每次登都要输入密码太麻烦。
于是想到了设置免登录
首先要生成公/私钥匙,
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ff:8e:85:68:85:94:7c:2c:46:b1:e5:2d:41:5c:e8:9b root@localhost.domain
既然是为了省事,密码为空即可,于是一路回车。
在/root/.ssh下面会生成两个文件id_rsa id_rsa.pub。
id_rsa.pub就是公钥,把它改个名放到目标服务器上,以后就可以无密码登录了。
感觉就像放了一匹特洛伊木马在服务器上。
scp /root/.ssh/id_rsa.pub 193.160.31.22:/root/.ssh/authorized_keys
要注意的是,如果别人已经在服务器上放了木马,你不能直接覆盖,需要在已有的/authorized_keys文件后面追加。
否则别人就无法免密码登录了。
于是想到了设置免登录
首先要生成公/私钥匙,
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ff:8e:85:68:85:94:7c:2c:46:b1:e5:2d:41:5c:e8:9b root@localhost.domain
既然是为了省事,密码为空即可,于是一路回车。
在/root/.ssh下面会生成两个文件id_rsa id_rsa.pub。
id_rsa.pub就是公钥,把它改个名放到目标服务器上,以后就可以无密码登录了。
感觉就像放了一匹特洛伊木马在服务器上。
scp /root/.ssh/id_rsa.pub 193.160.31.22:/root/.ssh/authorized_keys
要注意的是,如果别人已经在服务器上放了木马,你不能直接覆盖,需要在已有的/authorized_keys文件后面追加。
否则别人就无法免密码登录了。
相关文章推荐
- 删除字符串中出现次数最少的字符
- 使用apktool解包和打包apk
- 开发环境
- 织梦列表页调用文章标题和摘要
- NGUI DrawCall数量优化( 记录备忘 )
- hibernate的hql查询语句总结
- 修改tomcat配置文件来改变访问路径
- iOS UI之删除导航栏左侧按钮
- expandableListView的divider该溶液显示在黑色
- iOS 时间处理(转)
- 在AngularJS中何时应该使用Directives,Controllers或者Service
- 面试题14:调整数组顺序使奇数位于偶数前面
- 使用eclipse编写c++程序的配置问题
- 批处理中setlocal enabledelayedexpansion的作用详细整理
- Python多线程
- 谈谈linux c编程过程
- C++/CLI signing snk文件强命名
- AMQP 协议学习笔记之二(编程实战)
- linux 设置环境变量的方法
- iOS and OS X Network Programming Cookbook |Creating an echo server(Bonjour)(下)