gravity-sync icon indicating copy to clipboard operation
gravity-sync copied to clipboard

Gravity Sync 4.0.4 - Install with Custom SSH Port

Open jmcombs opened this issue 3 years ago โ€ข 2 comments
trafficstars

I am trying to install Gravity Sync (latest version) and use a different SSH port. I have tried running export GS_SSH_PORT='2222' && curl -sSL https://gravity.vmstan.com | bash and just running curl -sSL https://gravity.vmstan.com | bash to no avail.

Both time out on connecting to the remote host to (I presume) add the SSH Key and verify Pi-Hole is installed; obviously because it is trying over Port 22.

Failed Install Output
โžœ  ~ curl -sSL https://gravity.vmstan.com | bash
โˆž Gravity Sync Installation Script
ยป Validating User Permissions
โœ“ Sudo utility detected
โœ“ osadmin has sudo powers
ยป Validating Install of Required Components
โœ“ SSH has been detected
โœ“ GIT has been detected
โœ“ RSYNC has been detected
โœ“ Systemctl has been detected
ยป Performing Warp Core Diagnostics
โœ“ Local installation of Pi-hole has been detected
ยป Executing Gravity Sync Deployment
โˆž Cleaning up bash.bashrc
  You may need to exit your terminal or reboot before running 'gravity-sync' commands
โˆž Creating Gravity Sync Directories
Cloning into '/etc/gravity-sync/.gs'...
remote: Enumerating objects: 2775, done.
remote: Counting objects: 100% (220/220), done.
remote: Compressing objects: 100% (128/128), done.
remote: Total 2775 (delta 169), reused 94 (delta 90), pack-reused 2555
Receiving objects: 100% (2775/2775), 606.50 KiB | 5.18 MiB/s, done.
Resolving deltas: 100% (1774/1774), done.
โˆž Starting Gravity Sync Configuration
โˆž Initializing Gravity Sync (4.0.4)
โœ“ Evaluating arguments: CONFIGURE
โœ“ Creating new gravity-sync.conf

  Welcome to the Gravity Sync Configuration Wizard
  Please read through https://github.com/vmstan/gravity-sync/wiki before you continue
  Make sure that Pi-hole is running on this system before your configure Gravity Sync

ยป Gravity Sync Remote Host Settings
โ€บ Remote Pi-hole host address
? IP: 192.168.7.21
โœ“ Saving 192.168.7.21 host to gravity-sync.conf
โ€บ Remote Pi-hole host username
? User: osadmin
โœ“ Saving [email protected] to gravity-sync.conf
ยป Gravity Sync SSH Key Settings
โœ“ Generating new SSH key
โœ“ Moving private key to /etc/gravity-sync/gravity-sync.rsa
โœ“ Moving public key to /etc/gravity-sync/gravity-sync.rsa.pub
โœ“ Loading gravity-sync.conf
โ€บ Registering SSH key to 192.168.7.21
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/etc/gravity-sync/gravity-sync.rsa.pub"
ssh: connect to host 192.168.7.21 port 22: Connection timed out
โœ“ SSH key registered to 192.168.7.21
ยป Pi-hole Installation Settings
โœ“ Detecting local Pi-hole installation
โœ“ Default install of Pi-hole detected
โˆž Detecting remote Pi-hole installationssh: connect to host 192.168.7.21 port 22: Connection timed out
โœ— Detecting remote Pi-hole installation

  Configuration has been completed successfully, once Gravity Sync has been installed your other
  node, your next step is to push all of the of data from the currently authoritative
  Pi-hole instance to the other.
  ex: gravity-sync push

  If that completes successfully you can automate future sync jobs to run at a regular interval on
  both of your Gravity Sync peers.
  ex: gravity-sync auto

โˆž Gravity Sync CONFIGURE completed after 664 seconds

So, I wait for install to timeout and fail and run gravity-sync config 2222 and it also fails:

Failed gravity-sync config output
โžœ  ~ gravity-sync config 2222
โˆž Initializing Gravity Sync (4.0.4)
โœ“ Evaluating arguments: CONFIGURE
! TARGET HOST SSH PORT SET TO 2222
! gravity-sync.conf already exists
โ€บ Proceeding will replace your existing configuration
? Type EJECT THE WARP CORE to confirm: EJECT THE WARP CORE
โœ“ Erasing existing gravity-sync.conf
โœ“ Creating new gravity-sync.conf

  Welcome to the Gravity Sync Configuration Wizard
  Please read through https://github.com/vmstan/gravity-sync/wiki before you continue
  Make sure that Pi-hole is running on this system before your configure Gravity Sync

ยป Gravity Sync Remote Host Settings
โ€บ Remote Pi-hole host address
? IP: 192.168.7.21
โœ“ Saving 192.168.7.21 host to gravity-sync.conf
โ€บ Remote Pi-hole host username
? User: osadmin
โœ“ Saving [email protected] to gravity-sync.conf
ยป Gravity Sync SSH Key Settings
โœ“ Using existing SSH key
โœ“ Saving custom SSH port to gravity-sync.confH port to gravity-sync.conf
โœ“ Saving custom SSH port to gravity-sync.conf
โ€บ Registering SSH key to 192.168.7.21
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/etc/gravity-sync/gravity-sync.rsa.pub"
[email protected]: Permission denied (publickey).
โœ“ SSH key registered to 192.168.7.21
ยป Pi-hole Installation Settings
โœ“ Detecting local Pi-hole installation
โœ“ Default install of Pi-hole detected
โˆž Detecting remote Pi-hole [email protected]: Permission denied (publickey).
โœ— Detecting remote Pi-hole installation

  Configuration has been completed successfully, once Gravity Sync has been installed your other
  node, your next step is to push all of the of data from the currently authoritative
  Pi-hole instance to the other.
  ex: gravity-sync push

  If that completes successfully you can automate future sync jobs to run at a regular interval on
  both of your Gravity Sync peers.
  ex: gravity-sync auto

โˆž Gravity Sync CONFIGURE completed after 13 seconds

Looking through this, it seems to be because the public SSH key is not getting pushed to the secondary server:

โˆž Detecting remote Pi-hole [email protected]: Permission denied (publickey).

So, I manually add /etc/gravity-sync/gravity-sync.rsa.pub to the remote host and vice versa:

more /etc/gravity-sync/gravity-sync.rsa.pub
<ssh key>

SSH into remote host and add key and confirm it is there

echo '<ssh key>' >> ~/.ssh/authorized_keys
more ~/.ssh/authorized_keys

I re-run gravity-sync config 2222 and it states successful

Successful gravity-sync config output
โžœ  ~ gravity-sync config 2222                   
โˆž Initializing Gravity Sync (4.0.4)
โœ“ Evaluating arguments: CONFIGURE
! TARGET HOST SSH PORT SET TO 2222
! gravity-sync.conf already exists
โ€บ Proceeding will replace your existing configuration
? Type FIRE ALL PHASERS to confirm: FIRE ALL PHASERS
โœ“ Erasing existing gravity-sync.conf
โœ“ Creating new gravity-sync.conf

  Welcome to the Gravity Sync Configuration Wizard
  Please read through https://github.com/vmstan/gravity-sync/wiki before you continue
  Make sure that Pi-hole is running on this system before your configure Gravity Sync

ยป Gravity Sync Remote Host Settings
โ€บ Remote Pi-hole host address
? IP: 192.168.7.21
โœ“ Saving 192.168.7.21 host to gravity-sync.conf
โ€บ Remote Pi-hole host username
? User: osadmin
โœ“ Saving [email protected] to gravity-sync.conf
ยป Gravity Sync SSH Key Settings
โœ“ Using existing SSH key
โœ“ Saving custom SSH port to gravity-sync.confH port to gravity-sync.conf
โœ“ Saving custom SSH port to gravity-sync.conf
โ€บ Registering SSH key to 192.168.7.21
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/etc/gravity-sync/gravity-sync.rsa.pub"
[email protected]: Permission denied (publickey).
โœ“ SSH key registered to 192.168.7.21
ยป Pi-hole Installation Settings
โœ“ Detecting local Pi-hole installation
โœ“ Default install of Pi-hole detected
โœ“ Detecting remote Pi-hole installation
โœ“ Remote install of Pi-hole detected

  Configuration has been completed successfully, once Gravity Sync has been installed your other
  node, your next step is to push all of the of data from the currently authoritative
  Pi-hole instance to the other.
  ex: gravity-sync push

  If that completes successfully you can automate future sync jobs to run at a regular interval on
  both of your Gravity Sync peers.
  ex: gravity-sync auto

โˆž Gravity Sync CONFIGURE completed after 11 seconds

I attempt to run gravity-sync push from the secondary device and it fails

gravity-sync push fail output
โžœ  ~ gravity-sync push       
โˆž Initializing Gravity Sync (4.0.4)
โœ“ Loading gravity-sync.conf
โœ“ Detecting local Pi-hole installation
โœ“ Detecting remote Pi-hole installation
โœ“ Gravity Sync remote peer is configured
โœ— Evaluating arguments ROOT
! osadmin has insufficient user rights for Gravity Sync
โˆž Gravity Sync ROOT exited after 1 seconds

Even though the installer verified the user had sufficient permissions, per https://github.com/vmstan/gravity-sync/issues/324#issuecomment-1097048032 I run sudo usermod -aG sudo osadmin on both devices and re-run gravity-sync push and it is successful.

Successful gravity-sync push
โžœ  ~ gravity-sync push            
โˆž Initializing Gravity Sync (4.0.4)
โœ“ Loading gravity-sync.conf
โœ“ Detecting local Pi-hole installation
โœ“ Detecting remote Pi-hole installation
โœ“ Gravity Sync remote peer is configured
โœ“ Evaluating arguments: PUSH
ยป Remote target [email protected]:2222
โœ“ Validating pathways to Pi-hole
โœ“ Validating pathways to DNSMASQ
โœ“ Hashing the remote Gravity Database
โœ“ Comparing to the local Gravity Database
! Differences detected in the Gravity Database
โœ“ Hashing the remote DNS Records
โœ“ Comparing to the local DNS Records
! Differences detected in the DNS Records
! DNS CNAMEs not detected on the local Pi-hole
! Static DHCP Addresses not detected on the local Pi-hole
! Replication of Pi-hole settings is required
โœ“ Performing backup of remote Gravity Database
โœ“ Performing backup of local Gravity Database
โœ“ Checking Gravity Database copy integrity
โœ“ Pushing the local Gravity Database
โœ“ Setting file ownership on Gravity Database
โœ“ Setting file permissions on Gravity Database
โœ“ Performing backup of remote DNS Records
โœ“ Performing backup of local DNS Records
โœ“ Pushing the local DNS Records
โœ“ Setting file ownership on DNS Records
โœ“ Setting file permissions on DNS Records
โœ“ Updating remote FTLDNS configuration
โœ“ Reloading remote FTLDNS services
โ€บ Performing replicator diagnostics
โœ“ Rehashing the remote Gravity Database
โœ“ Recomparing to local Gravity Database
โœ“ Rehashing the remote DNS Records
โœ“ Recomparing to local DNS Records
! DNS CNAMEs not detected on the local Pi-hole
! Static DHCP Addresses not detected on the local Pi-hole
โœ“ Saving updated data hashes
โœ“ Sending hashes to Gravity Sync peer
โœ“ Setting permissions on remote hashing files
โœ“ Logging successful PUSH
โˆž Gravity Sync PUSH completed after 28 seconds

So, my question is: Is this a defect or am I doing something wrong? Thank you!

jmcombs avatar Oct 10 '22 14:10 jmcombs

I figured this error out:

โˆž Detecting remote Pi-hole [email protected]: Permission denied (publickey).

I have PasswordAuthentication set to no in my SSH config /etc/ssh/sshd_config. Gravity Sync uses ssh-copy-id to copy over the Public Key and to do so, requires PasswordAuthentication to be set to yes (which makes sense).

It would be nice to do a check to see if PasswordAuthentication is off and, if so, present the user with the option to manually add the public key to the remote host and then come back and press any key to continue. Don't know if you accept PRs for this, happy to try and add the logic.

Other issues still remain:

  • Still digging through to see if its possible for me to specify the SSH port on initial install so I don't have to wait for it to error out just to run gravity-sync config 2222.
  • With regards to sudo usermod -aG sudo osadmin, I will try to mimic and reproduce this issue

jmcombs avatar Oct 11 '22 12:10 jmcombs

I have submitted this PR https://github.com/vmstan/gs-install/pull/4 to add the ability to specify a custom SSH port on install.

jmcombs avatar Oct 11 '22 18:10 jmcombs

Effective July 26, 2024, this project has been retired. Thank you for your use and enthusiasm for a project that began as a few lines of bash in a Slack channel and envolved into something far more complex, and used by many thousands of Pi-hole enthusiasts over the last four years.

vmstan avatar Jul 26 '24 18:07 vmstan