Web」カテゴリーアーカイブ

インターネット全般に関するカテゴリーです。

パスワードの入力なしでSSHを使う設定

SSH公開鍵を使ってログインする設定の手順です。

1. クラアント側で公開鍵を作成

$ ssh-keygen
Enter file in which to save the key (/home/username/.ssh/id_rsa): [Enterキー]
Enter passphrase (empty for no passphrase): [Enterキー]
Enter same passphrase again: [Enterキー]
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:*******************************************
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
+----[SHA256]-----+

※既に作成済みの場合は飛ばしてください。
※パスフレーズを空欄にしておけばログイン時のパスワード入力は省略できます。
※複数のサーバーで同じ鍵を使い回すことも可能です。

2. 公開鍵をサーバーに転送

scpで送る場合は次のような感じになります。
xxx.xxx.xxx.xxxの部分はサーバーのIPアドレスまたはドメイン名です。)

$ scp .ssh/id_rsa.pub username@xxx.xxx.xxx.xxx:/home/username/

送信できたら、サーバーにログインして次のような感じで登録できます。

$ cat id_rsa.pub .ssh/authorized_keys
$ rm -i id_rsa.pub

以上で設定完了です。

ちなみに、サーバー側に.sshディレクトリがない場合はmkdirで作成してください。

$ mkdir .ssh
$ chmod 700 .ssh

3. パスワードによるログインを禁止する(おまけ)

パスワード入力によるログインを禁止して、公開鍵でのログインのみ許可するようにしたい場合は/etc/ssh/sshd_configに以下のような設定を追加してください。

PasswordAuthentication no

セキュリティ的には向上すると思いますが、万が一の場合にもパスワードでログインできなくなるので気を付けてください。

※設定の変更後はsystemctlなどでsshdの再起動(もしくは設定更新)を忘れずに。

改行したくない場合はwhite-space:nowrap

改行したくない場合はCSSにwhite-space: nowrapと記載するとよいそうです。

nowrapなし

style="width: 5em"
あいうえおかきくけこさしすせそ

nowrapあり

style="width: 5em; white-space: nowrap"
あいうえおかきくけこさしすせそ

リンク

white-space – CSS: Cascading Style Sheets | MDN
https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

Apache2.4でのアクセス制限の書き方

Apache2.4では2.2で使っていたOrder allow,denyなどの記述が変更され、新しい書き方になったみたいです。ということで、その書き方を調べてみました。

アクセス制限の書き方

mod_authz_coreを使ったアクセス制限の書き方

全てのアクセスを許可する

<Directory "/admin">
  Require all granted
</Directory>

従来の書き方

<Directory "/admin">
  Order allow,deny
  Allow from all
</Directory>

全てのアクセスを拒否する

<Directory "/admin">
  Require all denied
</Directory>

従来の書き方

<Directory "/admin">
  Order allow,deny
  Deny from all
</Directory>

特定のIPのみアクセスを許可する

<Directory "/admin">
  Require ip 123.456.789.012
</Directory>

従来の書き方

<Directory "/admin">
  Order deny,allow
  Deny from all
  Allow from 123.456.789.012
</Directory>

特定の環境変数がある場合のみアクセスを許可する

<Directory "/admin">
  Require env value
</Directory>

従来の書き方

<Directory "/admin">
  Order deny,allow
  Deny from all
  Allow from env=value
</Directory>

リンク

mod_authz_core – Apache HTTP Server Version 2.4
http://httpd.apache.org/docs/current/mod/mod_authz_core.html

Upgrading to 2.4 from 2.2 – Apache HTTP Server Version 2.4
http://httpd.apache.org/docs/2.4/upgrading.html