Here, we will edit the file on Linux with Visual Studio Code that runs on Windows. Here we use ubuntu 20.04.1.
I think there are many similar articles, but I will keep a record of what I did.
SSH Remote plugin of Visual Studio CodeSSH Remote plug-in of Visual Studio Code (setting the location of the RSA private key)SSH Remote plug-in of Visual Studio Code (adding the Linux server to connect to)SSH Remote plugin of Visual Studio CodeExecute the following command to enable SSH by referring to https://qiita.com/m-tmatma/items/9a562863ca99ca6c0d1c.
sudo apt install -y openssh-server
sudo systemctl start ssh
sudo systemctl enable ssh
Start Tera Term and select SSH key generation from the menu

Make sure the key type is RSA, set the number of bits to 4096, and select generate.

If necessary, write a comment in the comment field for later reference.

Press Save Public Key.
At this time, you need to specify the save destination, but usually specify the folder % USERPROFILE% \ .ssh.
% USERPROFILE% means C: \ Users \ your username.
If this directory does not exist, create it with the following command.
mkdir %USERPROFILE%\.ssh
After creating the directory, specify it. Keep the default filename id_rsa.pub and press Save.
Save Private Key.Yes to leave the passphrase empty.

% USERPROFILE% \ .ssh, so that location is selected.id_rsa and press Save.Close button to close it.** The private key is very important information and you need to make sure it is not leaked. ** ** This information is similar to a password, so if it is leaked, you will be able to log in to the Linux server freely, so you need to manage it strictly.
id_rsa.pub (= RSA public key) into the Tera Term window.SCP checked, press OK.

If you run ls on the console of Tera Term, you can see that id_rsa.pub is transferred.
You need to make sure that you don't forward the id_rsa by mistake. (I made a mistake while writing this article)
Set up to log in using the transferred RSA public key. Place the transferred public key by referring to https://m-tmatma.github.io/ssh/auto_login.html.
mkdir -p ~/.ssh
cat id_rsa.pub >> .ssh/authorized_keys
rm id_rsa.pub
chmod 755 ~
chmod 700 ~/.ssh
This procedure removes id_rsa.pub as it is no longer needed.
SSH Authentication dialog that appears when you connect to the server is displayed.RSA / DSA / ECDSA / ED25519 Use Key checked.private key, specify the file path of the private key.

SSH Remote plug-in of Visual Studio CodeRemote --SSH and install it.
SSH Remote plug-in of Visual Studio Code (setting the location of the RSA private key)
SSH TARGETS to display the hidden icon. Click the setting icon.


The contents are as follows.
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host alias
HostName hostname
User user
Add the IdentityFile setting to this and save it.
It looks like the following
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host alias
HostName hostname
User user
IdentityFile C:\Users\winuser\.ssh\id_rsa.pub
SSH Remote plug-in of Visual Studio Code (adding the Linux server to connect to)SSH TARGETS and press the+button.

username @linux servername and press ENTER.


SSH Remote plug-in of Visual Studio Code (adding the Linux server to connect to)+ icon to open another window and confirm the OS. Select Linux and press ENTER. (Since I couldn't take a screenshot well, I omitted the screenshot). If you skip here, it will not connect well. The very first connection takes time as it sets up the server side behind the scenes.

Visual Studio Code window will open.
It looks like nothing has changed, but if you select Open Folder from the File menu, the path part will be / home / user as shown below, and it will be directly on the Linux server. You can open the file system.

192.168.11.56 folder.

New File from the File menu.

ls -l in the Tera Term window that is opened separately, you can see that the file has been created and matches the edited contents.

I opened the file on the server with Visual Studio Code in a separate window, but you can also open it in the same window.
Recommended Posts