schollz / find-lf

Track the location of every Wi-Fi device (:iphone:) in your house using Raspberry Pis and FIND
https://www.internalpositioning.com/plugins/#using-find-without-an-app
GNU Affero General Public License v3.0
1.01k stars 119 forks source link

Could not connect to RPi #29

Open chensteven opened 6 years ago

chensteven commented 6 years ago

When I try running python3 cluster.py initialize, I get "Could not connect to {'address': 'pi@..., 'notes': 'Test', 'wlan': 'wlan0'}"

Any way to debug this? Thank you.

arenasInnovared commented 6 years ago

I have the same problem

rpandey91 commented 6 years ago

Hi, as per the documents initialize command is for checking and updating scan.py. Use start command to start the cluster. Hope this will help you

chensteven commented 6 years ago

I found the problem. The program is trying to run the command "ssh-copy-id {'address': 'pi@172.31.72.83', 'notes': '83', 'wlan': 'wlan1'}" but ssh-copy-id can't take {...} as an argument. I'm not sure what happened there but if you remove that part of the code, it will work.

arenasInnovared commented 6 years ago

let me try this

arenasInnovared commented 6 years ago

When execute the cluster.py start this same raspberry don't run the scan.py program but the others yes. That it's normal?

Best Regards

BS1A commented 6 years ago

This is a mistake in the script https://github.com/schollz/find-lf/blob/f17ca7ed487fe64d0212f81164ab85a1c753fc46/tools/cluster.py#L375

elif command == "initialize": print("copying ips") for address in config['pis']: c = 'ssh-copy-id %(address)s r, code = run_command(c % {'address': address})

is feeding a JSON object to ssh-copy-id which obviously doesn't work. Instead it should only pass the address field of the current config['pis'] object.

To fix it simply change the code like here and it should work again.

arms203 commented 6 years ago

I get the same error. I also change the address to pi and another error occur, name address is not define. Please help.

BS1A commented 6 years ago

Make sure that you changed both lines 377 and 379 in the original cluster.py correctly (as described here).

Otherwise I'm afraid your error is of a different nature as originally described in this thread.

arms203 commented 6 years ago

Thank you for replying. Below is the changes that I have done

elif command == "initialize":
    print("copying ips")
    for pi in config['pis']:
        c = 'ssh-copy-id %(address)s'
        r, code = run_command(c % {'address':pi['address']})
        if code == 1:
            print("Could not connect to %s" % address)
            return
        logger.debug(r)
        logger.debug(code)

Below is the error message I got when running the code

Traceback (most recent call last): File "cluster.py", line 499, in main(args, config) File "cluster.py", line 381, in main print("Could not connect to %s" % address) NameError: name 'address' is not defined

BS1A commented 6 years ago

Ah, I forgot to change the print(...) argument to pi['address'] also. See my latest commit

About your error though: As I suspected your problem is not the same as the one described in this thread and even the latest change will not solve your problem (merely improves debugging). It seems your ssh-copy-id call is not successful, I suggest running ssh-copy-id with your RPi's [user@]hostname in the command line to see what the issue is.

arms203 commented 6 years ago

I think so too. Thanks for the tips.

503Dev commented 5 years ago

This is a great project, that being said, there are a few quirks (not really quirks but just normal config things) that need a bit of explaining, if you get the could not connect error, read these tips...

Idea: The "master" connects to the "slaves" via ssh and executes a python script (scan.py), for this to work there needs to be a passwordless connection with ssh and in addition the user connecting needs to be able to sudo without a password.

Issue: Could not connect. For me this happened because I didn't have SSH setup right to allow logins without a password. Could not start also occurs when there is no scan.py file or no privileges.

You can circumvent the initialization script and just manually prepare each raspberry pi, I had to do this running "Kali Pi" because the premade scripts didn't work. In my case I was using a non-pi master and two pi zero w's as slaves.

Here is how I got it to work:

  1. From the "master", run: sudo apt-get install openssh-client openssh-server nmap then, wget https://raw.githubusercontent.com/schollz/find-lf/master/tools/cluster.py and finally: ssh-keygen

  2. This will now make an ssh key in /home//.ssh , it's id_rsa.pub, you need to copy this to each slave pi, to do so run: ssh-copy-id username>@<IPADDRESS Note: Make sure the username exists on the slave pi, if your master is not a pi then it probably does not share a common username. In that case just login to the slave pi's as root and the do: sudo adduser and replace with whatever use you use on the master, rerun the ssh-copy-id once the user is added.

  3. On each slave pi run: visudo (as root or via sudo) edit the %sudo line and set to: %sudo ALL=(ALL:ALL) NOPASSWD: ALL

Note: This is insecure if these devices have potential remote access. You may consider adding your own group instead. In my case this was fine ....

  1. From the master, login to each slave via: ssh Note: If this does not work your SSH key is not setup right, see above. Make sure the .ssh directory on slaves is set to chmod 700 and owned by the user not root.

  2. If the SSH connections work ok then login to each slave and get the scan.py script by running this command: wget https://raw.githubusercontent.com/schollz/find-lf/master/node/scan.py -O scan.py

  3. Also get the pre-reqs, so run this on each slave pi: Run: apt-get update apt-get install -y htop vim python3 python3-requests apt-get install wireless-tools firmware-atheros usbutils wireshark tshark hostapd -y

  4. From the master you can now run python3 cluster.py initialize Enter the IP of each pi and leave the others as default. Make a group name. Ignore any errors that may be thrown as we used a non standard workflow.

  5. Run on master: python3.py cluster start

You should see each slave pi respond and either start the service or say it's already running!

503Dev commented 5 years ago

Two more things to add, on my setup even though it responded well it did not actually get any scan results, I logged into the slave pi's and manually ran the wireshark command that scan.py runs to debug and saw the issue is permissions. I had to do the following on each slave pi:

sudo dpkg-reconfigure wireshark-common

When prompted to allow non-superusers select YES/ALLOW

then run: sudo chmod +x /usr/bin/dumpcap

Reboot the slave pis and restart the scan on the cluster.