简体   繁体   English

两个EC2实例之间的Lsyncd

[英]Lsyncd between two EC2 instances

I have two EC2 instances and i am trying to sync a directory between the two of them. 我有两个EC2实例,我试图在两个实例之间同步目录。

I have set up the lsyncd service on one of the instances and was able to sync a directory to different directory on the same instance. 我已经在一个实例上设置了lsyncd服务,并且能够将目录同步到同一实例上的其他目录。 Now i am trying to sync the same directory with the second instance and it is not working. 现在,我正在尝试与第二个实例同步同一目录,但它不起作用。

The reason it is not working is that I am not able to put the key that was generated on the first instance using ssh-keygen -t rsa on the second instance in order to allow them access each other. 它无法正常工作的原因是,我无法将使用ssh-keygen -t rsa在第一个实例上生成的密钥放在第二个实例上,以允许它们彼此访问。

I have tried sudo ssh-copy-id -i /path/to/key ec2-user@ip-of-second-instance but it did not work. 我尝试了sudo ssh-copy-id -i /path/to/key ec2-user@ip-of-second-instance但它没有用。 I have also tried to manually copy the public part from the key.pub file of the first instance to the ~/.ssh/authorized_keys of the second instance but it did not work either. 我还尝试了将公共部分从第一个实例的key.pub文件手动复制到第二个实例的~/.ssh/authorized_keys ,但是它也不起作用。

That is my lsynd configuration settings: 那是我的lsynd配置设置:

settings = {
    insist = true,
    logfile = "/var/log/lsyncd/lsyncd.log",
    statusFile = "/var/log/lsyncd/lsyncd.status"}

sync {
        default.rsyncssh,
        source = "/home/ec2-user/IntSrv/Sync",
        host = "second-instance-ip",
        target = "/home/ec2-user/GenSrv/Sync",
}

What am i doing wrong? 我究竟做错了什么? How can i fix that issue? 我该如何解决该问题? Any help would be appreciated. 任何帮助,将不胜感激。 Thank you. 谢谢。

You might want to start again with the keys. 您可能想再次从按键开始。

You should really be generating your own keys for each user . 您确实应该为每个用户生成自己的密钥 Then, for each user you want to grant access to the instance, add their key to the .ssh/authorized_keys file, either for the ec2-user or preferably create a user account for them first and add it to their authorized_keys file. 然后,对于要授予该实例访问权限的每个用户,将其密钥添加到.ssh/authorized_keys文件中(对于ec2-user或者最好是首先为其创建一个用户帐户,然后将其添加到他们的authorized_keys文件中。

The keys generated by Amazon EC2 should be used to gain initial access to your instances. Amazon EC2生成的密钥应用于获得对实例的初始访问权限 Then, proper security practice is to remove that key and add your own keys. 然后, 正确的安全措施是删除该密钥并添加您自己的密钥。 This way, you have each person accessing via their own keypair, which can be removed if you wish to rescind access. 这样,每个人都可以通过自己的密钥对进行访问,如果希望取消访问,可以将其删除。

While I'm not familiar with lsyncd , I suspect that if you get ssh working, then lsyncd will probably work fine, too. 虽然我对lsyncd并不熟悉, lsyncd我怀疑如果ssh正常工作,那么lsyncd也可能会正常工作。

So, quick summary: 因此,快速总结:

  • Generate a key for YOU using ssh-keygen 使用ssh-keygen为您生成密钥
  • Connect to the desired instances, and add your public keypair to authorized_keys within the desired user home directory 连接到所需实例,并将您的公共密钥对添加到所需用户主目录中的authorized_keys
  • Use those keys instead of the ones generated by Amazon EC2 使用这些密钥而不是Amazon EC2生成的密钥

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM