VSCode: How to change user (in order to have the permissions to save files) when connected via SSH to remote machine

Viewed 10

So far I have found the way to connect VScode to a remote machine of my company and to edit files directly by following this documentation and this tutorial.

However, I cannot save my files once edited, because the user I have declared in the configuration file for accessing remote hosts via SSH does not have the privileges to edit files.

popup from VScode as I try to save files

I know there are ways and VScode extensions allowing to save files remotely from VScode as sudo, but in my case I need to switch to another user than root to save those files, because this is the process stated in my company.

Let me clarify this:

When accessing remote hosts from my terminal, I have to access with a personal user, let's say user_P, and then turn to another user to edit files, let's say user_O, with

sudo -i -u user_O

So, to edit a file tentative.txt placed in /tmp/ of my remote host, I usually do, from my local machine

ssh user_P@<remote_machine_ip>
sudo -i -u user_O
vim /tmp/tentative.txt

and I cannot do

ssh user_O@<remote_machine_ip>
vim /tmp/tentative.txt

since user_O does not have permissions to access the remote host from my local machine.

So, If my VScode is connected to my remote host by using the configuration file

Host my_host
    HostName <my_host_IP> 
    User user_P
    IdentityFile /home/<my_local_user>/.ssh/known_hosts

and it is connected to remote folder /tmp/ , how can I "switch" to user_O and edit and save tentative.txt successfully?

Disclaimer:

I know accessing and editing files directly on remote machines is dangerous, but I am going to do it only on test enviromnments.

0 Answers
Related