LoginSignup
0
0

More than 1 year has passed since last update.

WebArena Indigo 環境設定3)他のサーバとのssh接続

Last updated at Posted at 2021-12-16

WebArena Indigo 環境設定2)ユーザ追加
https://qiita.com/naga_kt/items/c7b6e09e93570252314e
の続き。

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

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

$ cd ~/.ssh/
$ ls -lrt
total 8
-rw-------. 1 xxxxxxxx centos      405 Dec 10 06:29 authorized_keys
-rw-r--r--. 1 xxxxxxxx centos      577 Dec 10 10:16 known_hosts
drwx------. 2 xxxxxxxx centos      125 Dec 13 07:47 .
drwx------. 3 xxxxxxxx users      74 Dec 14 06:00 ..

 この状態でも他のサーバに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の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のサーバに接続するにはsshキーの公開鍵の登録が必要である。

sshキーの作成

 他のサーバからWebArena Indigoのサーバに接続するには、他のサーバでsshキーを作る必要がある。既にある場合はそれを用いればいい。
 ない場合、または古いタイプのdsaキーではそのままでは登録できない。
 ない場合はssh-keygenでsshキーを作る。ない場合、例えば.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サーバに接続先のサーバの公開鍵を持ってくる。WebArena Indigoサーバ側で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-r--r--. 1 xxxxxxxx centos      577 Dec 10 10:16 known_hosts
-rw-------. 1 xxxxxxxx centos      814 Dec 10 10:25 authorized_keys
$cp -p authorized_keys authorized_keys-bak
$cat ../id_rsa.pub >>authorized_keys

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

$ 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!
Last login: Tue Dec 14 06:28:17 2021 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!
Last login: Tue Dec 14 07:21:13 2021 from ・・・・
$

WebArena Indigo 環境設定4)時間設定の変更
https://qiita.com/naga_kt/items/194dfcd70f72d977187d
に続く。


参考記事

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