#author("2021-03-08T19:39:02+09:00","default:ham","ham")
#author("2021-03-08T19:42:26+09:00","default:ham","ham")
#contents
#br

* 概要 [#s5b18d72]

- SSH [Secure Shell]
-- セキュアな Telnet
- SCP [SSH Copy]
-- セキュアな RCP
- SFTP [SSH File Transfer Protocol]
-- セキュアな FTP
-- FTPS [File Transfer Protocol over SSL] とは異なる
** リンク [#o4327930]

- OpenSSH
-- http://www.openssh.com/
- STACK* - OpenSSHで暗号化通信
-- http://www.stackasterisk.jp/tech/systemConstruction/openssh01_01.jsp
* インストール [#t2fd3580]

 % ./configure                                     \
         --prefix=/usr/local/openssh               \
         --sysconfdir=/etc/ssh                     \
         --with-zlib=/usr/local                    \
         --with-tcp-wrappers=/usr                  \
         --with-ssl-dir=/usr/local/openssl
 % make
 # make install


* 設定 [#af8c05ff]

*** /etc/ssh/sshd_config [#p455b7e1]

rootのssh接続を拒否する
 PermitRootLogin no
パスワードが設定されていないアカウントを拒否する
 PermitEmptyPasswords no
rhosts認証関係の設定
 RhostsAuthentication no
 RhostsRSAAuthentication no
 IgnoreRhosts yes

** パスワードなしログイン [#k1f2f22c]

- 公開鍵を利用した認証を行い、パスワード入力をスキップする

+ 鍵の作成
#pre(soft){{
host$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Created directory '/home/user/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:RKbymBUosufI1qYrrAyS8UO8ipl4RHWWXReFuYNmRsE user@host
The key's randomart image is:
+---[RSA 4096]----+
|     ..oooo.o=.  |
|. . o +=. E.o    |
| o o.oo .. . .   |
|..o  * .  = o    |
|o=+ o . S+   .   |
|.Bo+             |
|*.*              |
|B*..             |
|X+.              |
+----[SHA256]-----+
}}
+ リモート ホストに公開鍵を保存
#pre(soft){{
rt-host$ cat id_dsa.pub > ~/.ssh/authorized_keys2
}}
*** $HOME/.ssh/id_dsa [#i41c8261]

- 秘密鍵
#pre(soft){{
-----BEGIN DSA PRIVATE KEY-----
MIIBvAIBAAKBgQDY+NZIVE5aQ+U8l381s841vnQI/aAIymGE1nYVVjaHOWcWQu8C
M61b14aMrsa1HmLAJyeIZHsG7119W3nJw2A6bIwFLEDoE48UHYZMYqlMuPWAg6Gw
BVFgyGUgQAlK18pDcvZrajq10pzkMtzLgVRjui+/ZLdqe/nz/VrdcG2x/QIVAIHv
k8Hrosq/hybk9b4/upd9/+lFAoGBALHn30L8MMIQtJjR16v9dY0/lfKAN74v5kiD
5zCTrx8ssEPynlXU7BJttqX1AGONqUkK1YNzLDsdUKtNO8gLsxfK9w6Fp9wAo8Mi
75Rrl4bEvg5SR6Vh2vn7y9SiSWYQNKbiz5rbpAN2Z0XrODK/1sADYGbUutXn5KZ1
ethcy25VAoGBAIQgdwpEDxhHgb0XPy8l2SDd7T8bIauTdPSyeqYWKpmnMaYtZ0kY
9jhP7nqBX1xUnRBgA6R8+7sssZHzSq8cuEEQlA7aDBHRKWzO3yP2R/QfyO46TfMM
6gQx1eMFB1ayNseo4QL6rYZLQjbWRfoBvpbHFnzt2MxGfKUn8q5AWPh/AhRF3fFF
AVp3F5qnGPSUnitCrtO2YQ==
-----END DSA PRIVATE KEY-----
}}

*** $HOME/.ssh/id_dsa.pub [#ebbb569b]

- 公開鍵
#pre(soft){{
ssh-dss AAAAB3NzaC1kc3MAAACBANj41khUTlpD5TyXfzWzzjW+dAj9oAjKYYTWdhVWNoc5ZxZC7wIz
rVvXhoyuxrUeYsAnJ4hkewbvXX1becnDYDpsjAUsQOgTjxQdhkxiqUy49YCDobAFUWDIZSBACUrXykNy
9mtqOrXSnOQy3MuBVGO6L79kt2p7+fP9Wt1wbbH9AAAAFQCB75PB66LKv4cm5PW+P7qXff/pRQAAAIEA
seffQvwwwhC0mNHXq/11jT+V8oA3vi/mSIPnMJOvHyywQ/KeVdTsEm22pfUAY42pSQrVg3MsOx1Qq007
yAuzF8r3DoWn3ACjwyLvlGuXhsS+DlJHpWHa+fvL1KJJZhA0puLPmtukA3ZnRes4Mr/WwANgZtS61efk
pnV62FzLblUAAACBAIQgdwpEDxhHgb0XPy8l2SDd7T8bIauTdPSyeqYWKpmnMaYtZ0kY9jhP7nqBX1xU
nRBgA6R8+7sssZHzSq8cuEEQlA7aDBHRKWzO3yP2R/QfyO46TfMM6gQx1eMFB1ayNseo4QL6rYZLQjbW
RfoBvpbHFnzt2MxGfKUn8q5AWPh/ user@home
}}


* 使い方 [#r6069ec7]

** sshd [#s63d67a8]

#pre(soft){{
# ssh ['''option''']
}}
-- '''option'''
|オプション|意味|説明|h
|-f '''filename'''|file|設定ファイル|
|-T|test|拡張テスト モードで実行|
|-t|test|テスト モードで実行|

*** デフォルトの設定 [#z61f6a4f]

#pre(soft){{
# sshd -T -f /dev/null
port 22
addressfamily any
listenaddress [::]:22
listenaddress 0.0.0.0:22
usepam no
logingracetime 120
'''<snip>'''
ipqos af21 cs1
rekeylimit 0 0
permitopen any
permitlisten any
permituserenvironment no
}}

*** 設定ファイルを読み込み後の設定 [#r07d2997]

#pre(soft){{
# sshd -T
}}
** ssh [#lcc90795]


#pre(soft){{
# ssh ['''option'''] ['''username'''@]'''hostname'''[:'''port'''] ['''command''']
}}
-- '''option'''
|オプション|意味|説明|h
|-l|login name|ユーザー名を指定する&br;'''username'''@'''hostname''' でも指定可能|
|-p|port|ポート番号を指定する&br;'''hostname''':'''port''' でも指定可能|
|-t|tty|tty を強制的に割り当てる&br;対話形式の操作が可能になる (sudo のパスワード入力など)|
|-o|option|ssh_config で設定可能なオプションを使用する|
|-N|do not execute|リモート ホストでコマンドを実行しない (プロンプトを返さない)|
|-f|fork|バックグラウンドで実行する|
|-Q '''query_option'''|query||
|-T|||
-- '''hostname'''
--- 接続先サーバ
-- '''command'''
--- 接続先サーバにワンライナーでコマンドを実行する場合に指定
--- 省略した場合は接続先サーバの TTY を開いたままにする
-- '''query_option'''

*** ポートフォワード [#c76e9a03]
#pre(soft){{
# ssh -L '''local_port''':'''remote_host''':'''remote_port''' '''relay_host'''
}}

*** 対応アルゴリズム [#v66bb89d]

- 対応する共通鍵暗号アルゴリズム
#pre(soft){{
# ssh -Q cipher
3des-cbc                     &color(red){OpenSSH 6.7でデフォルト無効};
aes128-cbc                   &color(red){OpenSSH 6.7でデフォルト無効};
aes192-cbc                   &color(red){OpenSSH 6.7でデフォルト無効};
aes256-cbc                   &color(red){OpenSSH 6.7でデフォルト無効};
rijndael-cbc@lysator.liu.se  &color(red){OpenSSH 6.7でデフォルト無効};
aes128-ctr
aes192-ctr
aes256-ctr
aes128-gcm@openssh.com
aes256-gcm@openssh.com
chacha20-poly1305@openssh.com
}}

- supported symmetric ciphers that support authenticated encryption
#pre(soft){{
# ssh -Q cipher-auth
aes128-gcm@openssh.com
aes256-gcm@openssh.com
chacha20-poly1305@openssh.com
}}

- 対応する鍵交換アルゴリズム
#pre(soft){{
# ssh -Q kex
diffie-hellman-group1-sha1          &color(red){OpenSSH 6.7でデフォルト無効};
diffie-hellman-group14-sha1
diffie-hellman-group14-sha256
diffie-hellman-group16-sha512
diffie-hellman-group18-sha512
diffie-hellman-group-exchange-sha1  &color(red){OpenSSH 6.7でデフォルト無効};
diffie-hellman-group-exchange-sha256
ecdh-sha2-nistp256
ecdh-sha2-nistp384
ecdh-sha2-nistp521
curve25519-sha256
curve25519-sha256@libssh.org
sntrup4591761x25519-sha512@tinyssh.org
}}
-- 前半が鍵交換アルゴリズム、後半がハッシュアルゴリズム

- GSSAPI key exchange algorithms
#pre(soft){{
# ssh -Q kex-gss
gss-gex-sha1-
gss-group1-sha1-
gss-group14-sha1-
gss-group14-sha256-
gss-group16-sha512-
gss-nistp256-sha256-
gss-curve25519-sha256-
}}

- key types
#pre(soft){{
# ssh -Q key
ssh-ed25519
ssh-ed25519-cert-v01@openssh.com
ssh-rsa
ssh-dss
ecdsa-sha2-nistp256
ecdsa-sha2-nistp384
ecdsa-sha2-nistp521
ssh-rsa-cert-v01@openssh.com
ssh-dss-cert-v01@openssh.com
ecdsa-sha2-nistp256-cert-v01@openssh.com
ecdsa-sha2-nistp384-cert-v01@openssh.com
ecdsa-sha2-nistp521-cert-v01@openssh.com
}}

- certificate key types
#pre(soft){{
# ssh -Q key-cert
ssh-ed25519-cert-v01@openssh.com
ssh-rsa-cert-v01@openssh.com
ssh-dss-cert-v01@openssh.com
ecdsa-sha2-nistp256-cert-v01@openssh.com
ecdsa-sha2-nistp384-cert-v01@openssh.com
ecdsa-sha2-nistp521-cert-v01@openssh.com
}}

- non-certificate key types
#pre(soft){{
# ssh -Q key-plain
[root@dev-ickw-stg01 log]#  ssh -Q key-plain
ssh-ed25519
ssh-rsa
ssh-dss
ecdsa-sha2-nistp256
ecdsa-sha2-nistp384
ecdsa-sha2-nistp521
}}

- 対応するメッセージ認証符号アルゴリズム
#pre(soft){{
# ssh -Q mac
hmac-sha1
hmac-sha1-96
hmac-sha2-256
hmac-sha2-512
hmac-md5
hmac-md5-96
umac-64@openssh.com
umac-128@openssh.com
hmac-sha1-etm@openssh.com
hmac-sha1-96-etm@openssh.com
hmac-sha2-256-etm@openssh.com
hmac-sha2-512-etm@openssh.com
hmac-md5-etm@openssh.com
hmac-md5-96-etm@openssh.com
umac-64-etm@openssh.com
umac-128-etm@openssh.com
}}

- 署名アルゴリズム
#pre(soft){{
# ssh -Q sig
ssh-ed25519          &color(red){OpenSSH 6.5~};
ssh-rsa              &color(red){非推奨 デフォルト無効化予定};
rsa-sha2-256         &color(red){OpenSSH 7.2~};
rsa-sha2-512         &color(red){OpenSSH 7.2~};
ssh-dss              &color(red){OpenSSH 7.0でデフォルト無効に};
ecdsa-sha2-nistp256  &color(red){OpenSSH 5.7~};
ecdsa-sha2-nistp384  &color(red){OpenSSH 5.7~};
ecdsa-sha2-nistp521  &color(red){OpenSSH 5.7~};
}}
** SCP [#df1203a2]

#pre(soft){{
# scp ['''option'''] '''org_file copy_file'''
}}


** SFTP [#z9d26cb3]


#pre(soft){{
# sftp ['''option'''] '''username'''@'''hostname'''
}}

- ログイン後のコマンドは FTP と同じ

** ssh-keygen [#p44f84a9]

#pre(soft){{
# ssh-keygen '''option'''
}}
-- '''option'''
|オプション|意味|備考|h
|-b '''bits'''|bits|キーペアの鍵長|
|-f '''filename'''|file|ファイル名|
|-t '''type'''|type|公開鍵認証アルゴリズム&br;dsa, ecdsa, ed25519, rsa|
|-C '''comments'''|comments||
|-m ||鍵フォーマット (PEM, PKCS8, RFC4716)&br;デフォルトは OpenSSH 独自形式 (OpenSSH 7.8~)|
||||
||||

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS