当サイトは、アフィリエイト広告を利用しています

Ubuntuにsshでホスト名で接続する

作成日:2023月07月13日
更新日:2023年09月02日

WindowsからUbuntuにssh(パスワード接続)で
ホスト名を使って接続する方法をメモ。

WindowsからUbuntuに接続する場合は
Ubuntuマシンの

  • ipアドレス
  • ホスト名

を知る必要がある。 今回はWindowsTerminalを使ってホスト名で
Ubuntuに接続する方法をまとめる。

TeraTermをつかっての接続や、ipアドレスでの接続方法については
下記記事でまとめています。

Ubuntuマシン側の操作

ホスト名を調べる

bash
$ hostnamectl

Static hostnameがhost名

host名
~
Static hostname: xxxxxx
~

openssh-serverをインストールする。

バージョンによってははSSHのサーバーパッケージがインストールされていないので。。

bash
$ sudo apt install openssh-server

/etc/ssh/sshd_configを編集する

パスワード認証を可能にする 初期状態ではパスワード認証がコメントアウトされているため
認証できない。

編集前

編集前はコメントアウトされている

sshd_config
vim /etc/ssh/sshd_config
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

コメントアウトをはずす

編集後

sshd_config
vim /etc/ssh/sshd_config
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no

これで設定は完了。

sshでつなぐマシンのIPアドレスを調べる

sshでつなぐUbuntuマシンのIPアドレスを調べる。
sshでつなぐためにはIPアドレスかマシン名が必要になる。

ipアドレス
ip address show

上記コマンド実行後にipアドレスが表示される。
※実際はもっと色々でてくるが探す!

ipアドレス
~
inet 192.168.0.9
~

sshでつなぐマシンのホスト名を調べる

host名を調べる

bash
hostnamectl

Static hostnameがhost名

host名
~
Static hostname: xxxxxx
~

上記で調べたipアドレスとホスト名を覚えておく
※Windows側で設定で使うので

Windowsマシン側の操作

下記のファイルを編集してipアドレスとホスト名を紐づけておく
ipアドレスとホスト名は上記で調べたUbuntuのものを追加する

/c/Windows/System32/drivers/etc/hosts
~
192.168.x.x ホスト名
~

これでWindows側の設定も完了

windowsTerminalからssh接続する

bash
$ ssh ユーザー名@ホスト名

入力後、ubuntuのユーザーのパスワードをいれれば接続できる

接続できない場合

ipアドレスとホストで名前解決が正しく行われているか確認する
windowsTerminalでpingコマンドで確認する

bash
ping ホスト名

実行後、/c/Windows/System32/drivers/etc/hostsで紐づけた

  • ipアドレス
  • ホスト名

がUbuntuで調べたipアドレスとホスト名になっているか確認する
違った場合は、/c/Windows/System32/drivers/etc/hostsを再度、正しく編集する。

参考

新着記事

タグ別一覧
top