1
2

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 5 years have passed since last update.

仮想環境のCentos7のファイルをVS codeでリモート編集する

Last updated at Posted at 2020-03-14

概略

VMwareを使って仮想マシン上にCentos 7をインストールした。centOS7上のファイルをもともとローカル環境(windows 10)にあったVS codeで編集したいと思い、VS codeのRemote Developmentを使って実行した。

環境

サーバー:centOS 7.7.1988
クライアント:windows 10 1903
VS code 1.42.1

VS codeのRemote Developmentの設定

VS codeの拡張機能であるRemote Developmentを使うことによって、リモートサーバーにssh接続をすることができます。VS codeの拡張機能追加(画像左端のメニューバーの四角形4つのアイコン)を選択して、検索ボックスに"Remote Development"と入力します。そうすると、Remote Developmentが検索結果として表示されるので、それをインストールします。
image.png

そしたら画面左下に表示される以下のアイコンをクリックします。
image.png

以下のような検索ボックスが起動するので、Remote-SSH:Connect to Host...を選択します。
image.png

続けてConfigure SSH Hosts...を選択します。
image.png

続けてC:\Users\ユーザ名\.ssh\configを選択します。下の画像ではユーザ名=keikeとなっています。
image.png

configファイルが起動するので、HostNameの後ろににsshサーバーのIPアドレス、Userの後ろにユーザ名を入力して保存します。なお、この設定はaliasというホスト名で保存されます。ホスト名を変えたい場合は画像中のaliasのところを変更してください。
image.png

事前の設定は以上です。

リモートサーバー(Centos 7)にsshで接続

ここからリモートサーバーへssh接続していきます。先ほどaliasという名前のホスト名で設定をしたので、Remote-SSH:Connect to Host...aliasと選択します。そうすると、VS codeの新しいウィンドウが起動し、接続先ホストのパスワードを求められるので、入力します。接続に成功すると、画面左下に以下のように表示されます。
image.png

試しにここでtest.phpというphpファイルを作ってリモートサーバー上に保存してみます。今のところ、以下の画像のようにリモートサーバ上のhomeにはファイルはありません。
image.png

test.phpはHello worldと表示するだけの簡単なファイルです。

test.php
<?php
    echo "Hello world\n";
?>

以下のように普通にVS codeでphpファイルを作成し、保存します。
image.png

これでcentos 7上にtest.phpが保存され、実行することもできます。
image.png

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?