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 1 year has passed since last update.

RockyLinux8 vps環境設定3) 他のサーバとのssh接続

Last updated at Posted at 2022-09-17

RockyLinux8 vps環境設定2) ユーザ追加
https://qiita.com/naga_kt/items/4b5cd8b37ef66018cec6
の続き。WebArena Indigo(RockyLinux8.4)及びKagoya(RockyLinux8.5)での環境設定について述べる。

現状での.sshディレクトリと接続

 ここまでではrocky/cloud-userの初期状態の.sshディレクトリをコピーして所有者・グループを変更しただけである。

$ cd ~/.ssh/
$ ls -lrta .ssh/
total 12
-rw------- 1 xxxxxxxx cloud-user  381 Sep 14 09:00 authorized_keys
drwx------ 2 xxxxxxxx cloud-user 4096 Sep 14 09:00 .
drwxr-x--x 3 xxxxxxxx users      4096 Sep 14 11:23 ..

 この状態でも他のサーバにssh接続することはできる。
 IPアドレス bbb.bbb.bbb.bbb のユーザaaaaaaaaにポート番号ccで接続する時、以下のようにすると接続できる。本当に接続するか聞かれ、接続先のパスワードを聞かれて入力すると接続することができる。

$ ssh -p cc aaaaaaaa@bbb.bbb.bbb.bbb
The authenticity of host '[bbb.bbb.bbb.bbb]:cc ([bbb.bbb.bbb.bbb]:cc)' can't be established.
RSA key fingerprint is ・・・・・・・・・・・・・・・・・・・・・・・・・・
RSA key fingerprint is ・・・・・・・・・・・・・・・・・・・・・・・・・・
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[bbb.bbb.bbb.bbb]:cc' (RSA) to the list of known hosts.
aaaaaaaa@bbb.bbb.bbb.bbb's password:
Last login: Wed Dec 15 08:28:31 2021 from ・・・・・・・・・・・・・
$

 ただし、これは一方通行であり、そのサーバからWebArena Indigo/KagoyaのIPアドレスyyy.yyy.yyy.yyyのユーザxxxxxxxxにポート番号zzzzzで接続しようとしてもできない。

$ ssh -p zzzzz xxxxxxxxx@yyy.yyy.yyy.yyy
The authenticity of host 'yyy.yyy.yyy.yyy (yyy.yyy.yyy.yyy)' can't be established.
RSA key fingerprint is ・・・・・・・・・・・・・・・・・・・・
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'yyy.yyy.yyy.yyy' (RSA) to the list of known hosts.
reverse mapping checking getaddrinfo for yyy-yyy-yyy-yyy.indigo.static.arena.ne.jp [yyy.yyy.yyy.yyy] failed - POSSIBLE BREAK-IN ATTEMPT!
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

 他のサーバからWebArena Indigo/Kagoyaのサーバに接続するにはsshキーの公開鍵の登録が必要である。

sshキーの作成

 他のサーバからWebArena Indigo/Kagoyaのサーバに接続するには、他のサーバでsshキーを作る必要がある。既にある場合はそれを用いればいい。
 ない場合、または古いタイプのdsaキーではそのままでは登録できない。
 ない場合はssh-keygenでsshのrsaキーを作る。ない場合、例えば.sshディレクトリの中は以下のようである。

$cd
$ls -lrta .ssh/
total 8
-rw-------. 1 aaaaaaaa users       405 Dec 10 06:29 authorized_keys
-rw-r--r--. 1 aaaaaaaa users       577 Dec 10 10:16 known_hosts

 ssh-keygenを実行する。オプションはデフォルトのままで問題ない。

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/aaaaaaaa/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/aaaaaaaa/.ssh/id_rsa.
Your public key has been saved in /home/aaaaaaaa/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:/・・・・・・・・・・・・・・・・・・・・・・・・
The key's randomart image is:
+---[RSA 2048]----+
|oo.=*@B+.o.      |
|..+.+*+Eo .      |
|.o .o.+. .       |
|=   =o o         |
|.+ .o=  S        |
|+.oo  o  .       |
|+=+    .  .      |
|+..     .  .     |
|         .o.     |
+----[SHA256]-----+

 これで.sshディレクトリに公開鍵id_rsa.pubと秘密鍵id_rsaができている。

$ ls -lrt .ssh/
total 16
-rw-------. 1 aaaaaaaa users    405 Dec 10 06:29 authorized_keys
-rw-r--r--. 1 aaaaaaaa users    403 Dec 10 07:17 known_hosts
-rw-r--r--. 1 aaaaaaaa users    405 Dec 10 08:09 id_rsa.pub
-rw-------. 1 aaaaaaaa users    1675 Dec 10 08:09 id_rsa

公開鍵の登録

 WebArena Indigo/Kagoyaサーバに接続先のサーバの公開鍵を持ってくる。WebArena Indigo/Kagoyaサーバ側でscpコマンドを用いてコピーすることができる。

$scp -P cc aaaaaaaa@bbb.bbb.bbb.bbb:/home/aaaaaaaa/.ssh/id_rsa.pub ~
The authenticity of host '[bbb.bbb.bbb.bbb]:cc ([bbb.bbb.bbb.bbb]:cc)' can't be established.
RSA key fingerprint is ・・・・・・・・・・・・・・・・・・・・・・・・・・
RSA key fingerprint is ・・・・・・・・・・・・・・・・・・・・・・・・・・
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[bbb.bbb.bbb.bbb]:cc' (RSA) to the list of known hosts.
aaaaaaaa@bbb.bbb.bbb.bbb's password:
id_rsa.pub                                    100%  409    67.0KB/s   00:00

 WebArena Indigoサーバで接続先のサーバの公開鍵を登録する。以下のように行なう。

$cd ~/.ssh/
$ls -lrt
total 24
-rw------- 1 xxxxxxxx cloud-user  381 Sep 14 09:00 authorized_keys
$cp -p authorized_keys authorized_keys-bak
$cat ../id_rsa.pub >>authorized_keys

 このように登録しておくと、接続先のサーバからssh接続すると以下のようになる。パスワードを入力せずにssh接続ができる。

【WebArena Indigo(RockyLinux8.4)の場合】

$ ssh -p zzzzz xxxxxxxxx@yyy.yyy.yyy.yyy
reverse mapping checking getaddrinfo for yyy-yyy-yyy-yyy.indigo.static.arena.ne.jp [yyy.yyy.yyy.yyy] failed - POSSIBLE BREAK-IN ATTEMPT!
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sat Sep 17 16:40:32 2022 from ・・・・
$

【Kagoya(RockyLinux8.5)の場合】

$ ssh -p zzzzz xxxxxxxxx@yyy.yyy.yyy.yyy
Last login: Fri Sep 16 14:29:12 2022 from ・・・・
$

 ここで
reverse mapping checking getaddrinfo for ・・・ failed - POSSIBLE BREAK-IN ATTEMPT!
というメッセージは、「逆引き DNS (PTR) レコードが一致しない」ということだ。どうすれば解決できるかは検討中。

.ssh/configファイルの設定

 .ssh/configに記述することでssh接続を簡略化することができる。
 接続先のサーバには既に.ssh/configがあったので、そこに以下を追記した。

Host    vps99 
HostName        yyy.yyy.yyy.yyy
Port            zzzzz
User            xxxxxxxx

 これでWebArena Indigoサーバにはvps99という名前で接続できるようになった。即ち、以下のようになる。

$ssh vps99
reverse mapping checking getaddrinfo for yyy-yyy-yyy-yyy.indigo.static.arena.ne.jp [yyy.yyy.yyy.yyy] failed - POSSIBLE BREAK-IN ATTEMPT!

Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sat Sep 17 16:40:32 2022 from ・・・・
$

RockyLinux8 vps環境設定4) 時間設定の変更
https://qiita.com/naga_kt/items/5b175dd606b459e92ebd
に続く。


参考記事

sshキー(秘密鍵・公開鍵)の作成と認証 流れ
https://qiita.com/soma_sekimoto/items/35845495bc565c38ae9d

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?