使用scp、ssh等不用输入密码
2009-04-02 21:16
344 查看
使用scp、ssh等不用输入密码
echo scp -r root@132.12.22.35:/www/applog /backlog > exp2.sh
echo scp -r /home/oracle root@10.10.252.5:/www/back/backdmp >> exp2.sh
scp -r root@132.12.22.35:/www/applog /backlog //备份日志
scp -r /home/oracle root@132.12.22.35:/www/back/backdmp //备份数据库
scp ~/.ssh/id_rsa.pub 132.12.22.35:/root/.ssh/authorized_keys
有些时候,我们在复制/移动文件到另一台机器时会用到scp,因为它比较安全。但如果每次
都要输入密码,就比较烦了,尤其是在script里。不过,ssh有另一种用密钥对来验证的方
式。下面写出生成密匙对的过程,供大家参考。
第一步:生成密匙对,我用的是rsa的密钥。使用命令 "ssh-keygen -t rsa"
[root@test ~]$ 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:
46:ed:89:18:f8:30:04:41:f5:72:b2:e6:66:27:20:73 root@test.test.com
[root@test ~]$
生成的过程中提示输入密钥对保存位置,直接回车,接受默认值就行了。接着会提示输入一
个不同于你的password的密码,直接回车,让它空着。 这样,密钥对就生成完了。
其中公共密钥保存在 ~/.ssh/id_rsa.pub
私有密钥保存在 ~/.ssh/id_rsa
然后改一下 .ssh 目录的权限,使用命令 "chmod 755 ~/.ssh"
[root@test ~]$ chmod 755 ~/.ssh
[root@test ~]$
之后把这个密钥对中的公共密钥复制到你要访问的机器上去,并保存为
~/.ssh/authorized_keys
[root@test ~]$ scp ~/.ssh/id_rsa.pub test2:/root/.ssh/authorized_keys
[email=root@test2's]root@test2's[/email] password:
id_rsa.pub 100% 228 3.2MB/s 00:00
[root@test ~]$
之这样就大功告成了。之后你再用ssh scp sftp 之类的访问那台机器时,就不用输入密码
了,用在script上更是方便。
echo scp -r root@132.12.22.35:/www/applog /backlog > exp2.sh
echo scp -r /home/oracle root@10.10.252.5:/www/back/backdmp >> exp2.sh
scp -r root@132.12.22.35:/www/applog /backlog //备份日志
scp -r /home/oracle root@132.12.22.35:/www/back/backdmp //备份数据库
scp ~/.ssh/id_rsa.pub 132.12.22.35:/root/.ssh/authorized_keys
有些时候,我们在复制/移动文件到另一台机器时会用到scp,因为它比较安全。但如果每次
都要输入密码,就比较烦了,尤其是在script里。不过,ssh有另一种用密钥对来验证的方
式。下面写出生成密匙对的过程,供大家参考。
第一步:生成密匙对,我用的是rsa的密钥。使用命令 "ssh-keygen -t rsa"
[root@test ~]$ 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:
46:ed:89:18:f8:30:04:41:f5:72:b2:e6:66:27:20:73 root@test.test.com
[root@test ~]$
生成的过程中提示输入密钥对保存位置,直接回车,接受默认值就行了。接着会提示输入一
个不同于你的password的密码,直接回车,让它空着。 这样,密钥对就生成完了。
其中公共密钥保存在 ~/.ssh/id_rsa.pub
私有密钥保存在 ~/.ssh/id_rsa
然后改一下 .ssh 目录的权限,使用命令 "chmod 755 ~/.ssh"
[root@test ~]$ chmod 755 ~/.ssh
[root@test ~]$
之后把这个密钥对中的公共密钥复制到你要访问的机器上去,并保存为
~/.ssh/authorized_keys
[root@test ~]$ scp ~/.ssh/id_rsa.pub test2:/root/.ssh/authorized_keys
[email=root@test2's]root@test2's[/email] password:
id_rsa.pub 100% 228 3.2MB/s 00:00
[root@test ~]$
之这样就大功告成了。之后你再用ssh scp sftp 之类的访问那台机器时,就不用输入密码
了,用在script上更是方便。
相关文章推荐
- 使用scp、ssh等不用输入密码
- 使用scp、ssh等不用输入密码
- 如何使用scp、ssh等命令不用手动输入密码
- 使用scp、ssh等不用输入密码
- 多客户端上传服务器 使用scp命令不用输入密码
- linux scp ssh命令不用输入密码
- 使用ssh传输文件不用输入密码
- ssh、scp的使用,以及shell脚本解决scp需要输入密码的问题
- ssh scp不用输入密码
- 在两台服务器之间建立信任关系解决scp,ssh等不用输入密码等问题
- java 使用 ssh 及 scp等 linux 命令、服务,输入密码免打断
- 在两台服务器之间建立信任关系解决scp,ssh等不用输入密码等问题
- 使用ssh或scp无需输入密码方法
- linux scp ssh命令不用输入密码
- 使用SSH访问IPhone不用输入密码
- 如何通过linux ssh远程linux不用输入密码登入-----scp命令可以本地与远程来回拖文件
- 在两台服务器之间建立信任关系解决scp,ssh等不用输入密码等问题
- 在两台服务器之间建立信任关系解决scp,ssh等不用输入密码等问题
- 在两台服务器之间建立信任关系解决scp,ssh等不用输入密码等问题
- 使用sshpass进行ssh/scp/sftp/自动输入密码