0
0

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.

Conoha で VPS を借りて SSH で公開鍵認証できるまで

Posted at

Mac から VPS へ SSH で接続するまでの作業ログ。
大した作業じゃないけどすぐ忘れるので自分用にメモ

環境

Conoha の VPS

Conoha コントロールパネルでサーバーを追加する。
今回は アプリケーション:LAMP を指定。
現時点では CentOS 8 らしい。

作業ユーザー作成

クライアント環境から VPS にログインする

追加したサーバーの詳細画面から IP アドレスを確認し、root ユーザーでログイン

>>> ssh root@xxx.xxx.xxx.xxx -p 22

VPS に作業用ユーザーを作成

# adduser tukanpo
# passwd tukanpo

作成したユーザーを wheel グループに追加

# gpasswd -a tukanpo wheel

【追記】
後で apache グループにも追加した

sudo 設定ファイルを編集

# sudo visudo

2行目がコメントアウトされていたらコメントを外す

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL

秘密鍵・公開鍵の作成

作業ユーザーでサーバーにログインしなおす

VPS からログアウト

# exit

作業ユーザーでログイン

>>> ssh tukanpo@xxx.xxx.xxx.xxx -p 22

ユーザーの作業ディレクトリ直下に .ssh ディレクトリ作成

$ mkdir .ssh
$ chmod 700 .ssh

ログアウトして再びクライアントに切り替える

クライアントで鍵を作成する

まだ未作成の場合は .ssh ディレクトリ作成

>>> cd ~
>>> mkdir .ssh
>>> chmod 700 .ssh
>>> cd .ssh

鍵を生成する (すでに存在していて使い回しでよければ不要)

>>> ssh-keygen -t rsa -b 2048

クライアントの公開鍵をサーバーにコピーする

公開鍵をサーバー側の authorized_keys にコピーする

>>> scp id_rsa.pub tukanpo@xxx.xxx.xxx.xxx:~/.ssh/authorized_keys

ホスト名で接続可能にする

.ssh ディレクトリの config ファイルを編集(なければ作成)

>>> vi config

下記を追加

Host tukanpo.net
  HostName xxx.xxx.xxx.xxx
  User tukanpo
  Port 22
  IdentityFile ~/.ssh/id_rsa

ホスト名で VPS に接続

>>> ssh tukanpo.net

おわり

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?