ぽっぽこメモ太郎

短くて分かりやすい備忘録を目指しています

Windows10(ホストOS)上に Windows10(ゲストOS)を構築する

目的

VirtualBox + Vagrant で、Windows10 上に Windows10 の仮想環境を構築したい

きっかけ

Windows10 上で開発することになったが、Windows10をそのまま開発に使うのは個人的に好きじゃない。
開発環境を切り離したいが、職場の都合で Docker は使えない為。

ちなみに、普段の開発では VirtualBox + Vagrant で構築した Linux環境 (Ubuntu, CentOS) で開発している。

環境

OS

ツール

つまづいた所

  • vagrant up の途中でエラーが出る
  • ゲストOSに自動でログインしてくれない

手順

boxファイル準備

公式が用意してくれている box ファイル を使用する。
このOSはブラウザテスト用らしいが、評価版OSとの違いは不明。

Virtual MachinesMSEdge on Win10 (x64) StableChoose a VM platformVagrant を選択して zipファイルをダウンロードするだけ。
お手軽。

f:id:hato_poppo_maru:20201108012137p:plain

ダウンロードした zip ファイルは解凍して、中身をVagrantfileと同じフォルダに格納した。
名前が長いのはあまり好きじゃないのでwin10.boxにリネーム。

Vagrantfile生成

仮想マシン用のフォルダを作成し、そこにVagrantfileを生成する。 Vagrantfile が何なのかは割愛。

今回は E:\Development\Vagrant\win10-dev を使うことにした。
以下、GitBash でのコマンド実行。
※ cdコマンド以外は コマンドプロンプトでも同じコマンドで実行可能

  • 移動
$ cd /e/Development/Vagrant/win10-dev
  • Vagrantfile生成
$ vagrant init

これで E:\Development\Vagrant\win10-dev に Vagrantfile が生成される。

Vagrantfile修正

いくつかの記事を参考にすると、以下のような記述が多かった。
※この設定ではうまくいかなかった。ホストOSの差か?

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "./win10.box"
  config.vm.guest = "windows"
  config.ssh.username = "IEUser"
  config.ssh.password = "Passw0rd!"
  config.ssh.insert_key = false

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:

  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

    # Customize the amount of memory on the VM:
    vb.memory = 1024 * 4
  end

  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

仮想環境構築開始

以下のコマンドで仮想環境を立ち上げることが出来る。
初回は諸々の環境構築を行うので、結構時間がかかる。

$ vagrant up

通常であれば問題なく進むが、今回は以下のようなエラーが発生した。

==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: IEUser
    default: SSH auth method: password
    default: Warning: Connection reset. Retrying...
    default: Warning: Connection aborted. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

出力内容からすると、ssh 接続でタイムアウトになっているような気がする。
というか Windowsssh 接続って簡単に出来るものなのか…?

この辺りの設定について Vagrant の公式 を眺めていると以下の記述を発見。

config.vm.communicator (string) - The communicator type to use to connect to the guest box. By default this is "ssh", but should be changed to "winrm" for Windows guests.

ゲストOSが Windows の場合は config.vm.communicator を "winrm" に変更する必要があるらしい。

※WinRM とは Windows Remote Management の略。 名前の通り Windows を遠隔操作する為の機能であるが、リモートデスクトップと違いコマンドで操作出来るらしい。

ということで、Vagrantfile に

config.vm.communicator = 'winrm'
config.winrm.username = 'IEUser'
config.winrm.password = 'Passw0rd!'

を追加する。

  • 変更後の Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "./win10.box"
  config.vm.guest = "windows"

  config.vm.communicator = "winrm"
  config.winrm.username = "IEUser"
  config.winrm.password = "Passw0rd!"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:

  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

    # Customize the amount of memory on the VM:
    vb.memory = 1024 * 4
  end

  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

vagrant up を再実行する。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 5985 (guest) => 55985 (host) (adapter 1)
    default: 5986 (guest) => 55986 (host) (adapter 1)
    default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: WinRM address: 127.0.0.1:55985
    default: WinRM username: IEUser
    default: WinRM execution_time_limit: PT2H
    default: WinRM transport: negotiate
==> default: Machine booted and ready!
[default] GuestAdditions versions on your host (6.1.4) and guest (6.0.4) do not match.
Copy iso file C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso into the box $env:TEMP/VBoxGuestAdditions.iso

~ 省略(Guest Additions アップデート関連)~

==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 6.0.4
    default: VirtualBox Version: 6.1
==> default: Mounting shared folders...
    default: /vagrant => E:/Development/Vagrant/win10-dev

いい感じに動作している。

ただ、ゲストOSに自動でログインしてくれない。 参考にした記事には自動でログインすると書いてあったが、ssh から winrm に変えたからなのか…。よく分からず。

ゲストOSの設定でやってしまう方が手っ取り早いかと思い調べてみると以下の記事の 自動サインインの設定 が参考になった。

Windows の起動時にパスワードを入力せず自動でログインする方法 (自動サインインの設定方法)

これで vagrant up 時のエラーは無くなり、自動でログインしてくれるようになった。 まだ日本語化が出来ていないが、そこはそのうち追記する。

まつもとゆきひろ コードの世界(第2章)

先日、久しぶりに「まつもとゆきひろ コードの世界」の第2章を読み返した。
10年以上前の本だけど今でも十分勉強になることが書いてあるので、読んだことの無い方は一度読んでみて欲しい。

tatsu-zine.com

今回は「動的型付け言語のデメリットを克服する方法」について、自分の感想も交えてメモしておく。

動的型付け言語のデメリットと対処方法について

エラーの発見が実行時になる

静的型付け言語であればコンパイル時にエラーが発見できるが、
動的型付け言語の場合は実行されるまで発見できない。

対処方法

単体テストをきっちりやる。
ちゃんとテストする習慣が定着していれば、静的型付け言語のようなコンパイル時のチェックが無くてもコードの信頼性は下がらない。

感想

テストをきっちりやることはとても重要。
問題があるとすれば、みんながみんなテストをきっちりやっているとは限らない という点か。

プログラムを読解する際のヒントが少ない

静的型付け言語であれば引数や変数の型がプログラム読解のヒントになり得るが、
動的型付け言語の場合は読解のヒントになる情報が少ない。

対処方法

ドキュメントを整備する。
Ruby には RDoc という標準ライブラリが用意されていて、Ruby で書かれたソースコードからドキュメントを自動生成できる。

library rdoc (Ruby 2.7.0 リファレンスマニュアル)
RDoc による自動ドキュメント生成

感想

正直な話、動的型付け言語だから読解に困った という経験が無い。
あった方が良いのは間違いないけど、デメリットと言うほどのものなのかどうかはよく分からない。

型云々の話ではないけど、プログラム読解についてはもっと別のところにポイントがある(変数に再代入しないとか)と思う。

それよりも気になったのが、ドキュメントの自動生成について「Ruby ドキュメント 自動生成」で簡単に調べてみたが最近の情報は出てこなかった。
特に目新しい情報が無いからなのか、ドキュメントの自動生成という対処方法自体が主流じゃなくなったからなのか…。

実行速度が遅い

同様の処理を行った場合、静的型付け言語と比べると動的型付け言語の方が実行速度が遅いことが多い。
実行時の型チェックのコストも影響していると思われるが、言語処理系がインタプリタコンパイラかという部分の影響が大きい。

対処方法(ではないけど)

昔よりもコンピューターの性能が向上しているので、大抵は実行効率よりも柔軟性や生産性の方が重要。

感想

動的型付け言語のメリットである、「柔軟性」と「生産性」はとても良いと思う。
ただ、システムを開発する上ではユーザビリティを考えると実行速度もあった方が嬉しい。

この辺りは2.6で実装されたJITコンパイルがもっと実用的になることに期待する。

まとめ

動的型付け言語にはデメリットもあるが、ちゃんと対応すれば克服できる という内容が書いてあった。
自分は静的型付けと動的型付けのどちらも好きだけど、言語としてはRubyが一番好きなのでこれからもRubyを使っていきたいと思っている。

Railsプロジェクト作成手順

rails プロジェクトを作成するときの手順を忘れて毎回ググるのでメモ
bundle install--path vendor/bundleは付ける派

環境

  • Ubuntu Server 18.04 LTS
  • rbenv 使用
  • binstubs 使用

手順

ディレクトリ作成

$ mkdir [project_name]
$ cd  [project_name]

Rubyバージョン指定

現在のバージョンをチェック

$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]

インストール済みのバージョンを確認

$ rbenv versions
  system
  2.6.6
* 2.7.1 (set by /home/[user_name]/.rbenv/version)

バージョン2.6.6を指定

$ rbenv local 2.6.6

結果確認

$ ruby -v
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]

プロジェクト作成準備

$ bundle config set path 'vendor/bundle'
$ bundle init
$ bundle binstubs --path=vendor/bin
`bundle binstubs` needs at least one gem to run.

→ エラーが出るけど無視でOK
  本来bundle binstubsを使う場合はbundle binstubs GEM [OPTIONS]のように
  gemを指定して実行するのでエラーが出ている。
  今回は.bundle/configファイルの生成&BUNDLE_BINのパス指定の為に実行するので無視してもOK(のはず)

$ vi Gemfile
# gem "rails" のコメントアウトを解除

gemをインストールする

$ bundle install

Railsプロジェクト作成

$ rails new . [オプション]
Overwrite /home/[user_name]/rails_projects/[project_name]/Gemfile? (enter "h" for help) [Ynaqdhm] y

vagrant + プロキシ環境にdocker導入

プロキシを通していない環境(自宅)は問題なかったけど、プロキシを通している環境(職場)では色々躓いたのでメモ

公式のインストール手順 に沿って進めた

環境

  • ホストPC
  • ゲストPC

躓いた所

  • docker インストール直後からcurlコマンドが通らなくなった
  • docker インストール後、動作確認の為に$ sudo docker run hello-worldを実行するとエラーが出る

curl が通らなくなる件

外部サイトへのcurlが、dockerを入れた直後から通らなくなった

$ curl www.google.com
curl: (7) Failed to connect to [プロキシサーバー] port [ポート]: No route to host

ping は通る

$ ping www.google.com

以下の記事がとても参考になった
docker bridge networkのIPアドレス指定での落とし穴(bip指定しても172.17.0.0/16から通信できなくなった)

上の記事と同様の対応でいけそうだったのでそのまま拝借

daemon.jsonを生成

$ sudo vi /etc/docker/daemon.json

以下の記述を追加

{
    "default-address-pools":[  
        {  
            "base":"192.168.0.0/16",
            "size":24
        }
    ]
}

再試行

$ curl www.google.com

→ 成功

docker run でエラーが出る件

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

→ 自宅の環境で試したときは問題なかったのでプロキシが怪しい

オプションでプロキシ設定を追加してみる

$ sudo docker run hello-world --env HTTP_PROXY="[プロキシサーバー]:[ポート]" --env HTTPS_PROXY="[プロキシサーバー]:[ポート]"
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

→ 結果変わらず。

dockerのステータスを確認してみる

$ sudo service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2020-09-29 22:33:07 JST; 1 day 1h ago
     Docs: https://docs.docker.com
 Main PID: 3500 (dockerd)
    Tasks: 11
   CGroup: /system.slice/docker.service
           └─3500 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

/lib/systemd/system/docker.serviceというファイルをロードしているらしい
ここにプロキシ設定を追加してみる

$ sudo vi /lib/systemd/system/docker.service

[Service]の設定項目に以下を追加

Environment="HTTP_PROXY=[プロキシサーバー]:[ポート]" "HTTPS_PROXY=[プロキシサーバー]:[ポート]"

更新を反映

$ sudo systemctl daemon-reload
$ sudo service docker restart

プロキシ設定が反映されていることを確認

$ sudo docker info

~省略~

 HTTP Proxy: [プロキシサーバー]:[ポート]
 HTTPS Proxy: [プロキシサーバー]:[ポート]

再試行

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:4cf9c47f86df71d48364001ede3a4fcd85ae80ce02ebad74156906caff5378bc
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

→ 成功

docker runにオプションでプロキシ設定を追加した時はうまくいかなかった理由が分かっていない

docker インストール手順

公式のインストール手順 ほぼそのまま。
apt-getaptに読み替えたくらいだけど、一応メモしておく。

$ sudo apt remove docker docker-engine docker.io containerd runc
$ sudo apt update
$ sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
$ sudo apt update
$ sudo apt install docker-ce docker-ce-cli containerd.io

Git でよく使うコマンド

よく使うやつコマンドをメモ

変更の退避

-uオプションを付与することにより、新規追加ファイルも同時に退避してくれる

$ git stash -u

退避した変更を一覧表示

$ git stash list

退避した状態を戻す

$ git stash apply stash@{0}

ローカルで変更したファイルを元に戻す

$ git checkout HEAD [file_name]

git add(ステージング)の取り消し

基本的に最新のコミットに戻すことが多いので、[commit_hash]HEADを指定する

$ git reset [commit_hash] [file_name]

追跡しないファイルとして扱う(ファイルは残したまま)

$ git rm --cached [file_name]

リモートリポジトリとの差分比較

$ git diff -- [file_name]

コミット済みタグ付け

$ git tag -a [tag_name] -m '[comment]' [commit_hash]
$ git push origin [tag_name]

sshd_config の設定変更

以前の記事 で挙げていた項目の中でも出来るだけ早めにやっておきたいこと

特にパスワード認証は早めに無効化しておきたい

手順

/etc/ssh/sshd_configファイルの編集をする

$ sudo vi /etc/ssh/sshd_config

今回設定の変更を行うのは後述の2点

パスワード認証の無効化

# 変更前
PasswordAuthentication yes

# 変更後
PasswordAuthentication no

rootユーザーのssh接続を無効化

# 変更前
PermitRootLogin yes

# 変更後
PermitRootLogin no

目的

ssh接続の設定を適切に行い、不正アクセスからサーバーを守る

公開鍵認証の有効化

以前の記事 で挙げていた項目の中でも一番最初にやっておきたいこと

ここでは公開鍵認証についての説明はしないが、以下の記事が参考になると思う
→ SSHの公開鍵認証における良くある誤解の話 - Qiita

環境

  • ローカル環境
  • サーバー環境
    • OS:Ubuntu Server 18.04 LTS

注意

本記事の手順はパスワード認証でサーバーに接続出来る状態であることが条件
後述する手順の「サーバーに公開鍵登録」で以下のようなエラーが出る場合はサーバー側の設定でパスワード認証が無効になっている可能性がある

 [ユーザー名]@[サーバーIP]: Permission denied (publickey).

また、パスワード認証を許可する際は特定されやすいユーザー名、パスワードは厳禁
例)ユーザー名とパスワードが両方とも user

これらに加えてデフォルトポート (22) を使用していると、簡単に不正アクセスされてしまう(実体験)

手順

キーペア生成

下記コマンドを実行する

$ ssh-keygen -t rsa -b 4096

ファイル名の入力を促されるが、デフォルト(id_rsa)で良い場合はそのまま Enterキー を押下

Enter file in which to save the key (/c/Users/[ユーザー名]/.ssh/id_rsa):

パスフレーズssh接続する際にパスワードの入力を要求されるようになる)も設定できるが、今回は設定しないのでそのまま Enterキー を押下

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

パスフレーズの使用/不使用について調べたが、気休め程度だという意見もあって入力の手間に見合う効果が得られるかどうかが分からないので調べている最中。

処理が終わるとログインユーザーのホームディレクトリ直下に.ssh/id_rsa.ssh/id_rsa.pubが生成される。

※鍵の保存先やファイル名を指定する場合

$ ssh-keygen -t rsa -b 4096 -f [ファイルパス]

オプションの-b 4096は鍵長を4096bitに指定する為に付与している
※参考
→  2017年版 SSH公開鍵認証で使用する秘密鍵ペアの作り方

サーバーに公開鍵登録 

公開鍵の保存先とファイル名がデフォルト (~/.ssh/id_rsa.pub) の場合

$ ssh-copy-id [接続ユーザー名]@[接続先IP or ホスト名]

ファイル名を指定する場合はこっち

$ ssh-copy-id -i [公開鍵 (.pubファイル) のパス] [接続ユーザー名]@[接続先IP or ホスト名]

接続確認

デフォルトの場合

$ ssh [接続ユーザー名]@[接続先IP or ホスト名]

ファイルを指定する場合

$ ssh -i [ファイルパス] [接続ユーザー名]@[接続先IP or ホスト名]

備考

ConoHaのVPSでは
https://support.conoha.jp/v/vps_sshkey/
に記載されている手順で出来るらしい