`
liangfuming
  • 浏览: 34902 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

ssh免密码登录配置

阅读更多
做转存的时候需要对源文件进行清理,bacula支持在执行完job后调用本地的sh脚本。
所以现在要在本地的sh中删除远程机器上的文件

在执行以下代码的时候,会出现密码输入:
linux_c2:~ # ssh   root@192.168.193.63 "rm -rf  /home/mysqlbackup/portal/122"
Password:

这样的做法达不到需求 必须输入密码这一环节省掉
在网上找到通过ssh 的rsa密钥进行密码验证

--首先通过以下方式生产密钥
linux_c2:~ # ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh‘.
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:
e0:f0:3b:d3:0a:3d:da:42:01:6a:61:2f:6c:a0:c6:e7 user1@rh.test.com
linux_c2:~ #

--生成密钥后到目录下查看密钥生成情况
linux_c2:~ # cd ~/.ssh/
linux_c2:~/.ssh # ll
total 32
-rw-r--r-- 1 root root  790 May 15 00:34 authorized_keys
-rw-r--r-- 1 root root 1206 Sep 29  2011 authorized_keys2
-rw------- 1 root root  668 Sep 29  2011 id_dsa
-rw-r--r-- 1 root root  603 Sep 29  2011 id_dsa.pub
-rw------- 1 root root 1675 Dec 23 10:49 id_rsa
-rw-r--r-- 1 root root  395 Dec 23 10:49 id_rsa.pub
-rw-r--r-- 1 root root 4345 May 29 09:53 known_hosts

--通过scp将密钥内容拷贝到远程服务器的authorized_keys文件中,没有这个文件,系统会新建。password是远程服务器密码
linux_c2:~/.ssh # scp ~/.ssh/id_rsa.pub 192.168.193.63:~/.ssh/authorized_keys
Password:
id_rsa.pub                                    100%  395     0.4KB/s   00:00   
linux_c2:~/.ssh #
--以上操作密钥配置完成,执行ssh不带密码也可以对远程服务器进行操作。
linux_c2:~ # ssh   root@192.168.193.63 "rm -rf  /home/mysqlbackup/portal/122"
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics