Forum Moderators: coopster

Message Too Old, No Replies

Accessing remote VPS as root

Trying to rync and edit on remote linux VPS from local machine

         

dstiles

2:11 pm on May 4, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have been trying to solve this for a couple of weeks, during which time I've read many web pages on the subject, made some adjustments, and failed.

Object:
To backup remote VPS to local computer using rsync.
To edit remote files such as web pages from local computer using (eg) Kate.
It would be useful but not essential to transfer files from local to remote direct into (eg) /srv.

I am using password-less ssh access with local ssh config as below. This works correctly for non-root access using thunar and terminal. I can also rsync from /srv (user www-data) and /home but only a few files can be transferred from / and /var. The return for non-transferred files/folders is "Permission denied (13)".
Host web
HostName (VPS IP)
Port (port number)
User (remote user)
PubKeyAuthentication yes
ForwardX11 yes
IdentityFile ~/.ssh/id_rsa

Remote sshd_config is
Port (port number)
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::

PermitRootLogin without-password

ChallengeResponseAuthentication no

UsePAM yes

AllowAgentForwarding yes
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
PrintMotd no

AcceptEnv LANG LC_*

Subsystemsftp/usr/lib/openssh/sftp-server

I have added the following to sudoers and altered the (user) to try to make it work:
(user) ALL=NOPASSWD: /usr/bin/rsync

A typical rsnc command run from cron on the local machine, where Phobos is the backup disk, is:
20 01 * * * dave rsync -r -t -p -o -g -x -u -l -H -E -X -D -s -m --stats --partial --log-file=/mnt/Phobos/web/aa-logs/root.log (sundry --excludes) -e ssh web:/ /mnt/Phobos/web/root/

lammert

2:49 pm on May 4, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"PermitRootLogin without-password" doesn't mean that root is allowed to login without a password. It means only authentication methods which do not use a password are allowed. Did you install the proper certificates in .ssh/authorized_keys?

The permission error indicates that the remote process is running as a normal user, not as user root.

dstiles

2:59 pm on May 4, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, auth keys in properly installed - it works fine for non-root.

I can believe the remote is not running as root but I cannot get it to do so.

GoneRogue

10:25 pm on May 4, 2021 (gmt 0)



Can you SSH as root (replace port 22 with whatever port ssh is configured to use)?
ssh -p 22 root@000.000.000.000


If so, then rsync as root:
-e "ssh -p 22" root@000.000.000.000:/ /mnt/Phobos/web/root/


That ^ replaces:
-e ssh web:/ /mnt/Phobos/web/root/


Also, it is a good idea to make certain rsync is installed/updated on both local and VPS and copies of the ssh keys have to be in the root directory.

dstiles

10:06 am on May 5, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a copy of the ssh config as above but with root instead of (user). That goes partway through and then asks for a password but won't accept any I can think of.

> copies of the ssh keys have to be in the root directory

YES! Thank you. That led to a new search, copied ~/.ssh files to /root/.ssh and all my dreams have come true!

You'd think some of the other searches I made would have mentioned it. :(

GoneRogue

3:19 pm on May 5, 2021 (gmt 0)



Glad you got it working!

lammert

3:31 pm on May 5, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



~/.ssh is /root/.ssh for the user root. '~' is replaced with the home directory mentioned in the /etc/passwd file for each user. The other resources you consulted probably assumed knowledge of the tilde path shortcut.

dstiles

10:13 am on May 6, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have always believed ~ meant absolutely the /home/user folder. Live and learn. :)