2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VSCodeでリモートサーバにSSHしてコーディングする方法

Last updated at Posted at 2020-07-01

構築環境

リモート側

$ cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)

クライアント側

Microsoft Windows [Version 10.0.18362.900]

設定手順

以下の公式手順に従い、設定した。

OpenSSHのインストール

OpenSSH互換のOpenSSHクライアントがインストールされている必要があると記載されている。

System requirements#
Local: A supported OpenSSH compatible SSH client must also be installed.

Microsoft公式手順で、OpenSSHをインストールする。PowerShellを管理者権限で起動し、以下のコマンドを実行する。

// OpenSSHクライアントをインストール
$ Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0


Path          :
Online        : True
RestartNeeded : False

// OpenSSHサーバをインストール
$ Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0


Path          :
Online        : True
RestartNeeded : False

// インストールされたことを確認
$ Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'


Name  : OpenSSH.Client~~~~0.0.1.0
State : Installed

Name  : OpenSSH.Server~~~~0.0.1.0
State : Installed

VSCodeのインストール

VSCode公式ページよりインストーラーをダウンロードし、インストールした。
https://code.visualstudio.com/

Remote Developmentのインストール

VSCode>Extensions>"Remote Development"と検索する。

iz04Ktp.png

"Remote Development"を選択して、インストールする。

リモートサーバへSSH接続準備

VSCode>View>Command Palette...>"Remote-SSH: Connect to Host...">"Configure SSH Hosts...">"Settings"を選択する。

yPR8Eih.png

Remote.SSH: Config Fileの箇所に、設定ファイルの配置パスを設定する。今回は「C:\command\vscode\ssh_config」に設定ファイルを配置した。

配置したssh_configに、下記SSHの設定を保存する。
※ 今回は鍵認証を使用したリモート接続の例である

Host [接続名]
    User [ユーザ名]
    HostName [IPアドレス]
    Port [ポート番号]
    IdentityFile [鍵パス]

※ 初回の接続は、File>Preferences>Settings>User>"Commonly Used">"Remote-SSH">"Remote.SSH: Show Login Terminal"をチェックしておくこと。なお、初回接続成功後は、チェックを外すこと。

リモートサーバへSSH接続

VSCode>Remote Explorer>SSH Targetsを選択する。

1vecsTc.png

設定した接続名が一覧に表示されているので、押下するとSSH接続が開始される。

rj0MI7I.png

プロンプトが表示されれば、接続に成功!

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?