LoginSignup
7
7

More than 5 years have passed since last update.

centosのSSHあたりのもろもろ

Last updated at Posted at 2015-10-13

SSHについて

SSH サーバーは CentOS を「Minimal Install」した場合でも、デフォルトで OpenSSH がインストールされるため、
追加インストールする必要はありません。
最低限必要な設定としては、セキュリティを考慮して、
以下のように root アカウントの直接ログインの禁止設定を実施する

vi /etc/ssh/sshd_config
# 42行目:コメント解除し変更 ( rootログイン禁止 )
PermitRootLogin no
# 65行目:コメント解除
PermitEmptyPasswords no
PasswordAuthentication yes
/etc/rc.d/init.d/sshd restart 

SSH クライアントをインストールします。(インストールしてない場合のみ)

# yum -y install openssh-clients

SSH鍵の作成

# 鍵ペア作成
#ssh-keygen -t rsa 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/[username]/.ssh/id_rsa):   # 変更の必要がなければそのまま空 Enter
Created directory '/home/[username]/.ssh'.
Enter passphrase (empty for no passphrase):   # パスフレーズ設定 (空 Enter でノーパス設定)
Enter same passphrase again:
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:
38:f1:b4:6d:d3:0e:59:c8:fa:1d:1d:48:86:f0:fe:74 [username]@dlp.server.world
The key's randomart image is:

#cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys 
#chmod 600 ~/.ssh/authorized_keys 

パスワードログインの不可

# vi /etc/ssh/sshd_config
# 66行目:パスワード認証不可に変更
PasswordAuthentication no
# /etc/rc.d/init.d/sshd restart 

SSHでのログイン

ssh [ログインユーザー@ホスト名 または IP アドレス]
ssh -i path/to/key/id_dsa ホスト名

SSHでリモートの任意コマンドの実行

例としてリモートホストの /etc/passwd を cat する
ssh cent@dlp.server.world "cat /etc/passwd"

7
7
1

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