MacからXServer VPSへSSH接続する手順です。
前提条件
- SSH Keyを設定済み
- SSH Keyは申込時に自動生成した(秘密鍵をダウンロード済み)
目次
MacからXServer VPSへSSH接続する手順
以下がMacからXServer VPSへSSH接続する手順になります。
- 秘密鍵のパーミッションを600へ変更
- ターミナルからsshコマンドでオプションで秘密鍵を指定して接続
MacからXServer VPSへSSH接続する方法
以下、実際にやった手順です。
エックスサーバーのサポートにMacからの接続がなかったので、まず「ネコでもわかる!さくらのVPS講座 ~第二回「サーバーをさわってみよう!」にある「Macの場合」を参考にして、sshコマンドを試しました。
ssh root@xxx.xxx.xxx.xxx
しかし次のようにPermission denied (publickey)
が表示され、接続ができませんでした。
The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established.
ED25519 key fingerprint is SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'xxx.xxx.xxx.xxx' (ED25519) to the list of known hosts.
root@xxx.xxx.xxx.xxx: Permission denied (publickey).
これは秘密鍵を指定していないことが原因で出たエラーになります。
-i
オプションで秘密鍵があるファイルパスを指定し、ssh
コマンドを実行します。
ssh root@xxx.xxx.xxx.xxx -i /Users/xxx/.ssh/filename.pem
今度はWARNING: UNPROTECTED PRIVATE KEY FILE!
と警告が表示されました。
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/xxx/.ssh/filename.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/Users/xxx/.ssh/filename.pem": bad permissions
root@xxx.xxx.xxx.xxx: Permission denied (publickey).
これは警告の下にあるようにファイルパーミッションが644であることが原因です。
次のコマンドをターミナルより実行して、秘密鍵のファイルパーミッションを変更します。
chmod 600 filename.pem
この状態で再度ssh
コマンドを実行します。
ssh root@xxx.xxx.xxx.xxx -i /Users/xxx/.ssh/filename.pem
接続が成功して、次のメッセージが表示されました。
Welcome to Ubuntu 25.04 (GNU/Linux 6.14.0-15-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of 2025年 7月 4日 金曜日 23:36:22 JST
System load: 0.0 Processes: 125
Usage of /: 8.9% of 47.35GB Users logged in: 0
Memory usage: 16% IPv4 address for ens3: xxx.xxx.xxx.xxx
Swap usage: 0%
14のアップデートはすぐに適用されます。
これらの追加アップデートを確認するには次を実行してください: apt list --upgradable
*** システムの再起動が必要です ***
root@x210-131-210-183:~#
以上がMacからXServer VPSへ接続する手順でした。
参考
SSH接続方法
https://vps.xserver.ne.jp/support/manual/man_server_ssh_connect.php