ssh到另一台机器不需要数据密码
2016-05-24 11:44
405 查看
原贴地址
http://rainbird.blog.51cto.com/211214/44357/
有些时候,我们在复制/移动文件到另一台机器时会用到scp,因为它比较安全。但如果每次
都要输入密码,就比较烦了,尤其是在script里。不过,ssh有另一种用密钥对来验证的方
式。下面写出我生成密匙对的过程,供大家参考。
第一步:生成密匙对,我用的是rsa的密钥。使用命令 "ssh-keygen -t rsa"
[user1@rh user1]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
e0:f0:3b:d3:0a:3d:da:42:01:6a:61:2f:6c:a0:c6:e7 user1@rh.test.com
[user1@rh user1]$
生成的过程中提示输入密钥对保存位置,直接回车,接受默认值就行了。接着会提示输入一
个不同于你的password的密码,直接回车,让它空着。当然,也可以输入一个。(我比较懒
,不想每次都要输入密码。) 这样,密钥对就生成完了。
其中公共密钥保存在 ~/.ssh/id_rsa.pub
私有密钥保存在 ~/.ssh/id_rsa
然后改一下 .ssh 目录的权限,使用命令 "chmod 755 ~/.ssh"
[user1@rh user1]$ chmod 755 ~/.ssh
[user1@rh user1]$
之后把这个密钥对中的公共密钥复制到你要访问的机器上去,并保存为
~/.ssh/authorized_keys.
[user1@rh user1]$ scp ~/.ssh/id_rsa.pub rh1:/home/user1/.ssh/authorized_keys
user1@rh1's password:
id_rsa.pub 100% 228 3.2MB/s 00:00
[user1@rh user1]$
之这样就大功告成了。之后你再用ssh scp sftp 之类的访问那台机器时,就不用输入密码
了,用在script上更是方便。
感谢这位网友,写的很详细。。。
使用无密码传输报错
解决方法
ssh-keygen -R IP
http://rainbird.blog.51cto.com/211214/44357/
有些时候,我们在复制/移动文件到另一台机器时会用到scp,因为它比较安全。但如果每次
都要输入密码,就比较烦了,尤其是在script里。不过,ssh有另一种用密钥对来验证的方
式。下面写出我生成密匙对的过程,供大家参考。
第一步:生成密匙对,我用的是rsa的密钥。使用命令 "ssh-keygen -t rsa"
[user1@rh user1]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
e0:f0:3b:d3:0a:3d:da:42:01:6a:61:2f:6c:a0:c6:e7 user1@rh.test.com
[user1@rh user1]$
生成的过程中提示输入密钥对保存位置,直接回车,接受默认值就行了。接着会提示输入一
个不同于你的password的密码,直接回车,让它空着。当然,也可以输入一个。(我比较懒
,不想每次都要输入密码。) 这样,密钥对就生成完了。
其中公共密钥保存在 ~/.ssh/id_rsa.pub
私有密钥保存在 ~/.ssh/id_rsa
然后改一下 .ssh 目录的权限,使用命令 "chmod 755 ~/.ssh"
[user1@rh user1]$ chmod 755 ~/.ssh
[user1@rh user1]$
之后把这个密钥对中的公共密钥复制到你要访问的机器上去,并保存为
~/.ssh/authorized_keys.
[user1@rh user1]$ scp ~/.ssh/id_rsa.pub rh1:/home/user1/.ssh/authorized_keys
user1@rh1's password:
id_rsa.pub 100% 228 3.2MB/s 00:00
[user1@rh user1]$
之这样就大功告成了。之后你再用ssh scp sftp 之类的访问那台机器时,就不用输入密码
了,用在script上更是方便。
感谢这位网友,写的很详细。。。
使用无密码传输报错
解决方法
ssh-keygen -R IP
相关文章推荐
- Ruby 之 class 中的 private、 protected、public
- Ruby定义私有方法(private)的两种办法
- sql2005 附加数据库出错(错误号:5123)解决方法
- C#中File类的文件操作方法详解
- asp #include file 与 #include virtual 的区别小结第1/2页
- PHP file_exists问题杂谈
- php类中private属性继承问题分析
- Ruby中的public、private、protected区别小结
- css美化input file按钮的代码方法
- 改变文件域的样式实现思路同时兼容ie、firefox
- How to Auto Include a Javascript File
- 清理SQL Server 2008日志文件Cannot shrink log file 2 的解决方案
- Locate a File Using a File Open Dialog Box
- Save a File Using a File Save Dialog Box
- 基于java file 文件操作operate file of java的应用
- php file_put_contents()功能函数(集成了fopen、fwrite、fclose)
- PHP 得到根目录的 __FILE__ 常量
- 解析php dirname()与__FILE__常量的应用
- IO流介绍与File类
- Python file 方法