4

I'm a little confused on how to run unison to sync files with group and owner attributes on an ubuntu system, as you need to be root. But I need to do this remotely and automated. I know I can set up ssh keys and the such for my user but that doesn't matter because I still wont be able to ssh as root to do the changes on the remote system.

I guess my question is; How would I go about using root on the remote system for unison? or is there a way of setting a command for a user to 'auto-run' as root without password?

Or are there any other ways that I could do this?

Any guidance with this is appreciated.

Elgoog
  • 225

3 Answers3

2

You should be able to setup ssh login with keys as you have stated.

Make sure your sshd_config allows root logins

PermitRootLogin without-password

Then copy the generated public-key to /root/.ssh/authorized_keys.

You should be able to login now, just tell unison to use the ssh key you generated.

Sig-IO
  • 1,076
  • 9
  • 11
1

Sudo can be configured to avoid asking for a password on some or all commands with the NOPASSWD parameter; but in any case I think it would be simpler to use ssh keys to access the remote system directly as root; after setting up passwordless authentication, unison should be called as follows:

unison a.tmp ssh://username@remotehostname/a.tmp
S19N
  • 1,933
0

Running Unison as root on a remote system carries security risks, and it's generally not recommended. However, if you have a specific use case that requires it, you can use sudo and SSH to execute the Unison command with root privileges on the remote system.

Here's a step-by-step guide:

Set Up SSH Key Authentication:

Make sure you have SSH key authentication set up for your user on both the local and remote systems. This will allow you to connect without entering a password.

On your local machine:

ssh-keygen -t rsa
ssh-copy-id user@remote_server

Replace user with your username and remote_server with the IP address or hostname of the remote server

Configure sudo on the Remote System:

You can configure sudo to allow your user to execute specific commands as root without entering a password. Be cautious when doing this, as it poses security risks.

Edit the sudoers file using visudo:

sudo visudo

Add the following line at the end of the file (replace yourusername and /path/to/unison with your actual username and Unison path):

yourusername ALL=(ALL) NOPASSWD: /path/to/unison

Save and exit the editor.

Run Unison Command:

ssh user@remote_server sudo /path/to/unison -batch -owner -group /path/on/local machine ssh://localhost:/path/on/remote/machine

Now, you can run Unison remotely using SSH and sudo, Again, keep in mind the security implications of running commands as root without a password. Ensure that your setup is secure and that you understand the risks involved. Always follow best practices for security when working with remote systems.