- 浏览: 115681 次
文章分类
转自:http://blog.tianya.cn/blogger/post_read.asp?BlogID=3668847&PostID=32922633
由于很多部门需要从公司服务器后台的数据库中去拉报表,
且因为每个部门对数据库表的需求、字段的需求不一样,
例如:
客服可能需要用户表、仓库产品表。
而产品部门却需要产品列表等。
这样会导致数据库反复的去检索查询数据库中的数据,并且在前段用户同时访问的情况下,这样就无形的导致
数据库系统以及操作系统的压力过大。
为解决这个问题,所以准备将数据库整个目录定时备份到另一台机器上,然后使得需要拉报表的人员从这台backup的机器上去拉报表。
========================================================================================================
问题出现:
但是这时候写脚本,问题就出现,因为我要从这个“执行脚本”的机器上面备份到另一台“接收数据”的机器上去。
这时候就想到了SCP命令。
但是我们知道在使用SCP命令的时候,其中因为安全机制的问题会跳出输入密码的部分,而且如果两台机器如果是第一次互相通信,
那么还会出现如下的需要确认的信息:
[root@test2 idaphne]# scp -rv 1.txt roo@192.168.2.70:/root/scripts/
Executing: program /usr/bin/ssh host 192.168.2.70, user roo, command scp -v -r -t /root/scripts/
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.2.70 [192.168.2.70] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
The authenticity of host '192.168.2.70 (192.168.2.70)' can't be established.
RSA key fingerprint is 3d:33:ce:58:2c:27:6a:bb:93:19:14:f7:7b:bc:42:8a.
Are you sure you want to continue connecting (yes/no)?
上面最后一行,就已经提示输入yes或是no了。这是两台机器建立临时信任机制的过程。
通过信息我们可以想到,scp命令使用是SSH服务的22端口进行通信。所以这一步输入“yes”
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.70' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: password
roo@192.168.2.70's password:
这时候,想如果使用没有密码的用户,是否就不会跳出输入密码的部分了呢?
尝试操作:
1、去掉接收文件机器上的密码:
[root@test1 ~]# passwd -d root
Removing password for user root.
passwd: Success
[root@test1 ~]#
2、尝试登录:
login as: root
root@192.168.2.70's password:
Access denied
3、执行脚本试一试:
[root@test2 idaphne]# scp -rv 1.txt roo@192.168.2.70:/root/scripts/
Executing: program /usr/bin/ssh host 192.168.2.70, user roo, command scp -v -r -t /root/scripts/
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
(中间信息略)
roo@192.168.2.70's password:
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
Permission denied, please try again.
roo@192.168.2.70's password:
4、说明:
删除root密码后,从机器终端是可以登录的,但在远程是无法登录的。
早期版本的linux如ReadHat8以前的版本,只要删除了root密码,在执行脚本后,需要输入密码的时候,输入任意字符就可以登录。
========================================================================================================
按照以上的方法是不成功的,查阅了大量资料后发现有一篇文章提及“scp和rsync的实际应用”,文章大致内容如下:
http://www.lslnet.com/linux/dosc1/30/linux-238181.htm
近段时间工作需要做了些scp和rsync的异地安全备份,整理了一下,希望多大家有用。
scp的备份指南:
需求:用scp自动完成异地文件的定时copy
难点:如何让异地主机建立安全的信任关系
1、在A机器上用root运行ssh-keygen,将生成/root/.ssh/identity和/root/.ssh/identity.pub两个文件;
2、在A机器上运行scp /root/.ssh/identity.pub test@192.168.1.10:/upload/.ssh/authorized_keys(假设B机器的IP地址为192.168.1.10,B机器上开了用户test,要上传到的目录是/upload,需输入密码)。目的是将本地的identity.pub放到远程机器上并改名为authorized_keys,这样就建立了新任主机,以后就不需要每次ssh都需要输入密码了;
3、通过crontab建立脚本,例:30 02 * * 1-5 scp /home/data/* test@192.168.1.10:/upload。
(每天2:30am自动将/home/data下面的所有文件以test用户名传到远程主机192.168.1.10的/upload目录中);
认证原理:
如果你希望从A作为用户user1 SSH 到B 作为用户user2, 若要用RSA键对法认证且不需要密码,则B上的ssh 后台程序拿出~user2/.ssh/authorized_keys中的与A有关的RSA公钥来对A上的以user1身份运行的ssh客户程序进行挑战,前面我们已经把A上的identity.pub拷贝到B上作为authorized_keys了。则A保持私钥identity,而B上的sshd又拿出A的公钥来挑战,因此成功,你可以加很多行到authorized_keys以允许其它服务器的公钥可以加进来。
scp特点:
使用ssl加密,安全性高。
rsync的备份指南:
需求:用rsync完成异地文件的同步
难点:如何建立异地信任关系
1、在A主机上(rsync服务器)上编译安装rsync,需要版本在2.4.3以上(http://rsync.samba.org),在/etc目录下建立rsyncd.conf文件,内容如下:
uid = nobody
gid = nobody
use chroot = no # 不使用chroot
max connections = 4 # 最大连接数为4
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock # 日志记录文件
[test] # 这里是认证的模块名,在客户端需要指定
path = /home/test # 需要同步的目录
comment = test folder
uid = root
ignore errors # 可以忽略一些无关的IO错误
read only = yes # 只读
list = no # 不允许列文件
auth users = rsynctest # 认证的用户名,如果没有这行,则表明是匿名
secrets file = /etc/test.scrt # 认证用户密码文件
2、在/etc下建立test.scrt文件,输入:
用户名:密码
例:rsynctest:testrsync
将文件属性修改为600(千万注意)
3、启动rsync服务:rsync --daemon (rsync运行在tcp 873端口,可以通过netstat -an|grep LISTEN察看)。
4、在B主机上(rsync客户机)上建立/etc/test文件,内容为A主机的密码,例:
testsync
5、用crontab建立脚本,例:0 21 * * 1-5 rsync -vzrtp --progress --delete --password-file=/etc/test rsynctest@192.168.1.10::test /home/rsynctest
rsync中的参数:v是verbose,z是压缩,r是recursive,tp都是保持文件原有属性如属主、时间
的参数。--progress是指显示出详细的进度情况,--delete是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。--password-file=/etc/test来指定密码文件,这样就可以在脚本中使
用而无需交互式地输入验证密码了,这里需要注意的是这份密码文件权限属性要设得只有属主可读(600)。
rsynctest@192.168.1.10中,rsynctest是指定密码文件中的用户名,192.168.1.10是A主机的IP地址::test是指模块名[test],也就是在/etc/rsyncd.conf中自定义的名称。最后的/home/rsynctest是备份到本地的目录名。
(也可以用-e ssh的参数建立起加密的连接,然后和scp中信任主机的办法一样如法炮制)
(在上面实例中的rsynctest并不是真实的用户,可以根据自己需要文本定义,这也是使用rsync的一大好处)
rsync的特点:
特性如下:
1、可以镜像保存整个目录树和文件系统。
2、可以很容易做到保持原来文件的权限、时间、软硬链接等等。
3、无须特殊权限即可安装。
4、优化的流程,文件传输效率高。
5、可以使用rcp、ssh等方式来传输文件,当然也可以通过直接的socket连接。
6、支持匿名传输。
rsync的功能还很强大,深入的眼就可以到官方网站上了解。
==========================================================================================================资料中介绍:
在两台机器的两个用户之间建立安全的信任关系后,可实现执行scp命令时不需要输入用户密码。
==========================================================================================================下面实现操作:
1、首先在“执行脚本”的机器上,root用户执行ssh-keygen命令,生成建立安全信任关系的证书:
[root@test2 idaphne]# ssh-keygen -b 1024 -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:
b5:2c:45:9a:6e:de:ff:f2:e0:1e:e6:bb:00:78:e6:f8 root@test2.rsync.com
[root@test2 idaphne]#
注意:
在程序提示输入passphrase时直接输入回车,表示无证书密码。
上述命令将生成私钥证书id_rsa和公钥证书id_rsa.pub,存放在用户家目录的.ssh子目录中。
[root@test2 idaphne]# cd /root/.ssh/
[root@test2 .ssh]# pwd
/root/.ssh
[root@test2 .ssh]# ls
id_rsa id_rsa.pub known_hosts
[root@test2 .ssh]#
2、将公钥证书id_rsa.pub复制到机器“接收数据的机器”的root家目录的.ssh子目录中,同时将文件名更换为authorized_keys。
[root@test2 .ssh]# scp -p id_rsa.pub root@192.168.2.70:/root/.ssh/authorized_keys
#输入机器“接收数据的机器”的root用户密码
root@192.168.2.70's password:
id_rsa.pub 100% 230 0.2KB/s 00:00
[root@test2 .ssh]#
可以看到这个步骤,还是需要输入密码的。
说明:
在执行传输文件“id_rsa.pub”所需要的命令时,两台机器的root用户之间还未建立安全信任关系,所以还需要输入机器“接收数据的机器”的root用户密码。
经过以上2步,就在机器“执行脚本”的root和机器“接收数据的机器”的root之间建立安全信任关系。
下面我们看看效果:
[root@test2 idaphne]# pwd
/usr/local/mysql/var/idaphne
[root@test2 idaphne]# ls
1.txt 2.txt 3.txt
[root@test2 idaphne]# scp -p 1.txt root@192.168.2.70:/usr/local/mysql/var/idaphne
1.txt 100% 2 0.0KB/s 00:00
[root@test2 idaphne]#
到这里,实验结束,结果是成功的,这样将scp命令中就不用在输入密码了。
下面另加一段:
当执行scp命令的时候,如果出现了如下错误:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
62:5a:5b:e3:be:5e:fa:ec:94:35:d2:de:db:c9:b1:f4.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:3
RSA host key for 192.168.2.70 has changed and you have requested strict checking.
Host key verification failed.
lost connection
这是因为:/root/.ssh/known_hosts记录rsa相关信息,删除,其中关于,上面错误中显示主机:192.168.2.70的记录即可。
由于很多部门需要从公司服务器后台的数据库中去拉报表,
且因为每个部门对数据库表的需求、字段的需求不一样,
例如:
客服可能需要用户表、仓库产品表。
而产品部门却需要产品列表等。
这样会导致数据库反复的去检索查询数据库中的数据,并且在前段用户同时访问的情况下,这样就无形的导致
数据库系统以及操作系统的压力过大。
为解决这个问题,所以准备将数据库整个目录定时备份到另一台机器上,然后使得需要拉报表的人员从这台backup的机器上去拉报表。
========================================================================================================
问题出现:
但是这时候写脚本,问题就出现,因为我要从这个“执行脚本”的机器上面备份到另一台“接收数据”的机器上去。
这时候就想到了SCP命令。
但是我们知道在使用SCP命令的时候,其中因为安全机制的问题会跳出输入密码的部分,而且如果两台机器如果是第一次互相通信,
那么还会出现如下的需要确认的信息:
[root@test2 idaphne]# scp -rv 1.txt roo@192.168.2.70:/root/scripts/
Executing: program /usr/bin/ssh host 192.168.2.70, user roo, command scp -v -r -t /root/scripts/
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.2.70 [192.168.2.70] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
The authenticity of host '192.168.2.70 (192.168.2.70)' can't be established.
RSA key fingerprint is 3d:33:ce:58:2c:27:6a:bb:93:19:14:f7:7b:bc:42:8a.
Are you sure you want to continue connecting (yes/no)?
上面最后一行,就已经提示输入yes或是no了。这是两台机器建立临时信任机制的过程。
通过信息我们可以想到,scp命令使用是SSH服务的22端口进行通信。所以这一步输入“yes”
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.70' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: password
roo@192.168.2.70's password:
这时候,想如果使用没有密码的用户,是否就不会跳出输入密码的部分了呢?
尝试操作:
1、去掉接收文件机器上的密码:
[root@test1 ~]# passwd -d root
Removing password for user root.
passwd: Success
[root@test1 ~]#
2、尝试登录:
login as: root
root@192.168.2.70's password:
Access denied
3、执行脚本试一试:
[root@test2 idaphne]# scp -rv 1.txt roo@192.168.2.70:/root/scripts/
Executing: program /usr/bin/ssh host 192.168.2.70, user roo, command scp -v -r -t /root/scripts/
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
(中间信息略)
roo@192.168.2.70's password:
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
Permission denied, please try again.
roo@192.168.2.70's password:
4、说明:
删除root密码后,从机器终端是可以登录的,但在远程是无法登录的。
早期版本的linux如ReadHat8以前的版本,只要删除了root密码,在执行脚本后,需要输入密码的时候,输入任意字符就可以登录。
========================================================================================================
按照以上的方法是不成功的,查阅了大量资料后发现有一篇文章提及“scp和rsync的实际应用”,文章大致内容如下:
http://www.lslnet.com/linux/dosc1/30/linux-238181.htm
近段时间工作需要做了些scp和rsync的异地安全备份,整理了一下,希望多大家有用。
scp的备份指南:
需求:用scp自动完成异地文件的定时copy
难点:如何让异地主机建立安全的信任关系
1、在A机器上用root运行ssh-keygen,将生成/root/.ssh/identity和/root/.ssh/identity.pub两个文件;
2、在A机器上运行scp /root/.ssh/identity.pub test@192.168.1.10:/upload/.ssh/authorized_keys(假设B机器的IP地址为192.168.1.10,B机器上开了用户test,要上传到的目录是/upload,需输入密码)。目的是将本地的identity.pub放到远程机器上并改名为authorized_keys,这样就建立了新任主机,以后就不需要每次ssh都需要输入密码了;
3、通过crontab建立脚本,例:30 02 * * 1-5 scp /home/data/* test@192.168.1.10:/upload。
(每天2:30am自动将/home/data下面的所有文件以test用户名传到远程主机192.168.1.10的/upload目录中);
认证原理:
如果你希望从A作为用户user1 SSH 到B 作为用户user2, 若要用RSA键对法认证且不需要密码,则B上的ssh 后台程序拿出~user2/.ssh/authorized_keys中的与A有关的RSA公钥来对A上的以user1身份运行的ssh客户程序进行挑战,前面我们已经把A上的identity.pub拷贝到B上作为authorized_keys了。则A保持私钥identity,而B上的sshd又拿出A的公钥来挑战,因此成功,你可以加很多行到authorized_keys以允许其它服务器的公钥可以加进来。
scp特点:
使用ssl加密,安全性高。
rsync的备份指南:
需求:用rsync完成异地文件的同步
难点:如何建立异地信任关系
1、在A主机上(rsync服务器)上编译安装rsync,需要版本在2.4.3以上(http://rsync.samba.org),在/etc目录下建立rsyncd.conf文件,内容如下:
uid = nobody
gid = nobody
use chroot = no # 不使用chroot
max connections = 4 # 最大连接数为4
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock # 日志记录文件
[test] # 这里是认证的模块名,在客户端需要指定
path = /home/test # 需要同步的目录
comment = test folder
uid = root
ignore errors # 可以忽略一些无关的IO错误
read only = yes # 只读
list = no # 不允许列文件
auth users = rsynctest # 认证的用户名,如果没有这行,则表明是匿名
secrets file = /etc/test.scrt # 认证用户密码文件
2、在/etc下建立test.scrt文件,输入:
用户名:密码
例:rsynctest:testrsync
将文件属性修改为600(千万注意)
3、启动rsync服务:rsync --daemon (rsync运行在tcp 873端口,可以通过netstat -an|grep LISTEN察看)。
4、在B主机上(rsync客户机)上建立/etc/test文件,内容为A主机的密码,例:
testsync
5、用crontab建立脚本,例:0 21 * * 1-5 rsync -vzrtp --progress --delete --password-file=/etc/test rsynctest@192.168.1.10::test /home/rsynctest
rsync中的参数:v是verbose,z是压缩,r是recursive,tp都是保持文件原有属性如属主、时间
的参数。--progress是指显示出详细的进度情况,--delete是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。--password-file=/etc/test来指定密码文件,这样就可以在脚本中使
用而无需交互式地输入验证密码了,这里需要注意的是这份密码文件权限属性要设得只有属主可读(600)。
rsynctest@192.168.1.10中,rsynctest是指定密码文件中的用户名,192.168.1.10是A主机的IP地址::test是指模块名[test],也就是在/etc/rsyncd.conf中自定义的名称。最后的/home/rsynctest是备份到本地的目录名。
(也可以用-e ssh的参数建立起加密的连接,然后和scp中信任主机的办法一样如法炮制)
(在上面实例中的rsynctest并不是真实的用户,可以根据自己需要文本定义,这也是使用rsync的一大好处)
rsync的特点:
特性如下:
1、可以镜像保存整个目录树和文件系统。
2、可以很容易做到保持原来文件的权限、时间、软硬链接等等。
3、无须特殊权限即可安装。
4、优化的流程,文件传输效率高。
5、可以使用rcp、ssh等方式来传输文件,当然也可以通过直接的socket连接。
6、支持匿名传输。
rsync的功能还很强大,深入的眼就可以到官方网站上了解。
==========================================================================================================资料中介绍:
在两台机器的两个用户之间建立安全的信任关系后,可实现执行scp命令时不需要输入用户密码。
==========================================================================================================下面实现操作:
1、首先在“执行脚本”的机器上,root用户执行ssh-keygen命令,生成建立安全信任关系的证书:
[root@test2 idaphne]# ssh-keygen -b 1024 -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:
b5:2c:45:9a:6e:de:ff:f2:e0:1e:e6:bb:00:78:e6:f8 root@test2.rsync.com
[root@test2 idaphne]#
注意:
在程序提示输入passphrase时直接输入回车,表示无证书密码。
上述命令将生成私钥证书id_rsa和公钥证书id_rsa.pub,存放在用户家目录的.ssh子目录中。
[root@test2 idaphne]# cd /root/.ssh/
[root@test2 .ssh]# pwd
/root/.ssh
[root@test2 .ssh]# ls
id_rsa id_rsa.pub known_hosts
[root@test2 .ssh]#
2、将公钥证书id_rsa.pub复制到机器“接收数据的机器”的root家目录的.ssh子目录中,同时将文件名更换为authorized_keys。
[root@test2 .ssh]# scp -p id_rsa.pub root@192.168.2.70:/root/.ssh/authorized_keys
#输入机器“接收数据的机器”的root用户密码
root@192.168.2.70's password:
id_rsa.pub 100% 230 0.2KB/s 00:00
[root@test2 .ssh]#
可以看到这个步骤,还是需要输入密码的。
说明:
在执行传输文件“id_rsa.pub”所需要的命令时,两台机器的root用户之间还未建立安全信任关系,所以还需要输入机器“接收数据的机器”的root用户密码。
经过以上2步,就在机器“执行脚本”的root和机器“接收数据的机器”的root之间建立安全信任关系。
下面我们看看效果:
[root@test2 idaphne]# pwd
/usr/local/mysql/var/idaphne
[root@test2 idaphne]# ls
1.txt 2.txt 3.txt
[root@test2 idaphne]# scp -p 1.txt root@192.168.2.70:/usr/local/mysql/var/idaphne
1.txt 100% 2 0.0KB/s 00:00
[root@test2 idaphne]#
到这里,实验结束,结果是成功的,这样将scp命令中就不用在输入密码了。
下面另加一段:
当执行scp命令的时候,如果出现了如下错误:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
62:5a:5b:e3:be:5e:fa:ec:94:35:d2:de:db:c9:b1:f4.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:3
RSA host key for 192.168.2.70 has changed and you have requested strict checking.
Host key verification failed.
lost connection
这是因为:/root/.ssh/known_hosts记录rsa相关信息,删除,其中关于,上面错误中显示主机:192.168.2.70的记录即可。
发表评论
-
Vi shortcut keys
2014-07-03 12:24 0删除所有行 gg dG 移动光标到第一行 ... -
How-to Install Oracle 12c Database on CentOS 6.X 64bit
2014-04-29 03:21 956http://blog.csdn.net/chncaesar ... -
64位Ubuntu 安装MySQL 5.5.32 错误记录与解决
2013-06-21 19:50 10821. dev.mysql.com/downloads 下载ta ... -
[转]JAVA_HOME配置 Ubuntu 11.04 下安装配置 JDK 7
2013-05-28 11:25 1216来源:http://blog.csdn.net/yang_hu ... -
[转载]给 ubuntu添加新硬盘 格式化和挂载
2013-03-27 15:56 1382转自 海阔天空 张翼飞翔http://www.cnweblog ... -
MySQL慢查询专题
2013-02-25 16:00 800相关命令: mysql> show variables ... -
[转]linux下shell批量修改文件后缀名
2012-12-17 18:26 1365转自 http://reeddeer.blog.163.com ... -
ubuntu 添加用户oracle到sudoers
2012-12-12 16:57 858/etc/sudoers 参照root所在行,添加 oracl ... -
Oracle linux 6.3配置静态IP地址和DNS
2012-12-12 16:35 2206ip & dns vi /etc/sysconfig/ ... -
Ubuntu网络相关设置
2012-12-12 11:09 818查看ip、网关等 ifconfig 重启网络服务 /etc/ ... -
配置IP之后ping不同,ifconfig打印出的信息有RX packets:234 errors:12字样
2012-12-13 12:52 1444原因 VirtualBox虚拟机默认网卡选择错误(公司用无线 ... -
转载: linux系统安装以后,通过命令模式配置网卡IP
2012-12-03 17:23 1327转自:http://qsfwy.iteye.com/blo ... -
install openssh-server on ubuntu
2012-11-29 15:11 9081.ps -e |grep ssh 2. sudo apt- ... -
configure /dev/shm before Install Oracle 11gR2 on Ubuntu 11.10 server (64-bit)
2012-11-29 11:41 719#! /bin/sh # /etc/init.d ... -
转载 - 为Ubuntu安装build-essential软件包(gcc)
2012-11-28 13:55 2870安装方法如下: $sudo apt-get instal ... -
Ubuntu server安装图形界面(桌面环境)
2012-11-27 14:00 2078sudo apt-get install xinit sud ...
相关推荐
1、远程登录到linux上,... #第一次ssh远程时会提示输入yes或者no client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #密码方式远程连接 client.connect(sys_ip, 22, username=username, password=p
在复制/移动文件从一台机器到另一台机器时会用到scp,因为它比较安全。但如果每次都要输入密码,就比较烦,尤其是在script里。不过ssh有另一种用密钥对来验证的方式。本文给出了生成密匙对的过程,供大家参考。
正常情况下,ssh登陆远程机器时会提示输入密码,这会影响到脚本的自动执行,(因为shell脚本中没有自动填充密码的命令)。 总的来说,有两个办法来解决问题: 1)建立主机间的ssh信任关系 2)用python...
使用Linux的程序员对输入密码这个举动一定不陌生,在Linux下对用户有严格的权限限制,干很多事情越过了权限就得输入密码,比如使用超级用户执行命令,又比如ftp、ssh连接远程主机等等,如下图: 那么问题来了,在...
使用pscp实现Windows 和 Linux服务器间远程传递文件 下载完成后,找到pscp.exe...它会提示你输入密码,就像Linux下使用scp那样。 d:\putty>pscp file root@IP:/root/ 1 或者 d:\putty>pscp -l root file IP:/root/
passwd + user 更改用户密码(不加user ,则更改当前用户密码) poweroff 关机 reboot 重启 vim vi 下 :wq 在vim or vi 后保存退出 :q 不保存退出 :q! 强制退出 在非insert 下可用 x来删除光标所在处字符 dw 可以...
为了克服这个问题,首先需要实现不需要密码的SSH登陆,这样就可以使用rsync,scp,rexec等命令来做的远程备份了。 1. 设置无需密码的ssh登陆,方法如下: 假设A,B两服务器,现在需要在A机上用root登陆B机,而...
如果系统检测到无效或非标准分区表标记,将提示用户是否继续执行该命令。除非您访问驱动器有问题,否则不要继续进行。向系统分区写入新的主引导记录可能破坏分区表并导致分区无法访问。 format 将指定的驱动器...
我们使用过mysqldump都知道,使用该命令后,需要我们手动输入 mysql的密码,那么我们就不能够直接在crontab中使用mysqldump实现周期备份。其实我们可以使用expect脚本自动输入密码,从而实现真正的周期备份。如果你...
在日常操作练习时,用ssh登录其他主机时,可能会每次都需要输入登录密码,哪怕用scp复制东西也需要。 为了更方便快捷的切换主机,ssh免密通信不失为更好的选择; 用ssh-keygen生成密钥,默认保存在本地的/root/.ssh/...
3.8.4 编辑并执行校正后的命令 76 3.8.5 命令行补充 77 3.9 命令别名 79 3.10 作业控制 81 3.11 会话记录与命令确认 83 3.11.1 保存会话记录 83 3.11.2 确保使用的命令是 ??正确的 84 第4章 文件系统基础知识 86 4.1...
3.8.4 编辑并执行校正后的命令 76 3.8.5 命令行补充 77 3.9 命令别名 79 3.10 作业控制 81 3.11 会话记录与命令确认 83 3.11.1 保存会话记录 83 3.11.2 确保使用的命令是 ??正确的 84 第4章 文件系统基础知识 86 4.1...
作为系统管理员,你计划在 Linux 上使用 OpenSSH,完成日常工作的自动化,比如文件传输、备份数据库转储文件到另一台...系统管理员用它来执行命令,以及通过 SCP 协议在网络上向另一台电脑传输文件。 通过配置 SSH