必要なもの
・Puttygenなど, RSA秘密鍵・公開鍵ペアを生成できるもの
・Puttyなど, SSH接続でサーバに接続しコンソール操作ができるもの
・WinSCPなど, SSH接続でファイルのやり取りができるもの
Puttygenの場合, こちらを参照(外部サイト)
鍵のビット数は2048とする
注意: パスフレーズはすぐ設定すること. また, 秘密鍵は絶対に他人に渡さないこと. もし秘密鍵の漏洩があった場合にはすぐにサーバ管理者へ連絡し, 再度鍵ペアを作り直すこと. (なお, 大学の規定ではパスフレーズは8文字以上とされています. )
で生成した鍵のうち, 公開鍵をメールやUSBなどでサーバ管理者に渡す.
具体的には下記サーバ側を参照. パスワードを入力するよう言われるので, 入力する.
Host Nameを10.9.105.101とする. Port番号は126.
左欄Connection->SSH->Authをクリックし, Private key file for authenticationのBrouwseボタンを押し, 1. で作った秘密鍵を登録する.
左欄Sessionをクリックし, Saved Session欄に適当な名前を入れ, Saveボタンをクリックする.
右下Openボタンをクリックし,
Using username "username".
Authenticating with public key "xxxxxxxxxxxxxx"
Passphrase for key "xxxxxxxxxxxxxx":
と表示されるので, パスフレーズを表示してEnterで
[username@saya7 ~]$
と表示されたら完了.
ホスト名に10.9.105.101 と入力する.
ユーザ名を入力する.
設定(D). . .をクリックし, 設定(D). . .欄をクリックして設定画面を開く.
左欄SSH ->認証をクリックし, 秘密鍵(K)欄右の. . .ボタンから1.で作った秘密鍵を登録する.
OKボタンをクリックし, 設定画面を閉じる.
保存ボタンをクリックし, 設定を保存する.
ログインボタンをクリックし, パスフレーズを入力してサーバにアクセスできれば設定完了.
suコマンドでスーパーユーザにログインする.
[yourname@saya7 ~]$ su
useraddコマンドでユーザを追加する.
[root@saya7 ~]$ useradd username
パスワードも設定する. 子ノードにログインする際に使う.
まず公開鍵を登録するためのディレクトリを作成する
[root@saya7 yp]# cd /home-saya7/
[root@saya7 home-saya7]# mkdir username
[root@saya7 home-saya7]# cd username
[root@saya7 username]# mkdir .ssh
次に, 公開鍵をサーバにアップロードし, 下記手順で変換する.
[root@saya7 username]# ssh-keygen -i -f (公開鍵ファイル名) > /home-saya7/username/.ssh/authorized_keys
MacやLinuxのssh-keygenコマンドでopensshの公開鍵を作成した場合には下記のようにそのままコピーすればよい.
[root@saya7 username]# cat (公開鍵ファイル名) > /home-saya7/username/.ssh/authorized_keys
最後に各パーミッションの設定. 通常のパーミッションとSELinuxのタグの両方を設定する必要がある.
[root@saya7 username]# semanage fcontext -a -t ssh_home_t /home-saya7/username/.ssh/authorized_keys
[root@saya7 username]# restorecon -RFv /home-saya7/username/.ssh/authorized_keys
[root@saya7 username]# cd .ssh
[root@saya7 .ssh]# ls -Z
これでauthorized_keyのタグがsysten_u:object_r:ssh_home_tになっていればOK. なっていない場合はrestoreconのオプションが間違っている可能性が高いのでもう一回
次に普通のパーミッションの設定
[root@saya7 .ssh]# cd ..
[root@saya7 username]# chown -R username:username .
[root@saya7 username]# chmod 700 .ssh
[root@saya7 username]# chmod 600 .ssh/authorized_keys
これでユーザのログインが可能となる.
[root@izanami ~]# yum -y install openldap-clients nss-pam-ldapd
[root@izanami ~]# authconfig --enableldap --enableldapauth --ldapserver=saya7 --ldapbasedn="dc=srv,dc=world" --enablemkhomedir --update
[root@izanami ~]# cat /etc/pam.d/system-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required pam_env.so
auth required pam_faildelay.so delay=2000000
auth [default=1 ignore=ignore success=ok] pam_succeed_if.so uid >= 1000 quiet
auth [default=1 ignore=ignore success=ok] pam_localuser.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 1000 quiet_success
auth sufficient pam_sss.so forward_pass
auth required pam_deny.so
account required pam_unix.so broken_shadow
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 1000 quiet
account [default=bad success=ok user_unknown=ignore] pam_sss.so
account required pam_permit.so
password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password sufficient pam_sss.so use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
-session optional pam_systemd.so
session optional pam_oddjob_mkhomedir.so umask=0077
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
session optional pam_sss.so
「pam_sss」を「pam_ldap」に変更
[root@izanami ~]# cat /etc/pam.d/system-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required pam_env.so
auth required pam_faildelay.so delay=2000000
auth [default=1 ignore=ignore success=ok] pam_succeed_if.so uid >= 1000 quiet
auth [default=1 ignore=ignore success=ok] pam_localuser.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 1000 quiet_success
auth sufficient pam_ldap.so forward_pass
auth required pam_deny.so
account required pam_unix.so broken_shadow
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 1000 quiet
account [default=bad success=ok user_unknown=ignore] pam_ldap.so
account required pam_permit.so
password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password sufficient pam_ldap.so use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
-session optional pam_systemd.so
session optional pam_oddjob_mkhomedir.so umask=0077
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
session optional pam_ldap.so
[root@izanami ~]# cat /etc/pam.d/password-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required pam_env.so
auth required pam_faildelay.so delay=2000000
auth [default=1 ignore=ignore success=ok] pam_succeed_if.so uid >= 1000 quiet
auth [default=1 ignore=ignore success=ok] pam_localuser.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 1000 quiet_success
auth sufficient pam_sss.so forward_pass
auth required pam_deny.so
account required pam_unix.so broken_shadow
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 1000 quiet
account [default=bad success=ok user_unknown=ignore] pam_sss.so
account required pam_permit.so
password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password sufficient pam_sss.so use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
-session optional pam_systemd.so
session optional pam_oddjob_mkhomedir.so umask=0077
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
session optional pam_sss.so
こちらも「pam_sss」を「pam_ldap」に変更
[root@izanami ~]# cat /etc/pam.d/password-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required pam_env.so
auth required pam_faildelay.so delay=2000000
auth [default=1 ignore=ignore success=ok] pam_succeed_if.so uid >= 1000 quiet
auth [default=1 ignore=ignore success=ok] pam_localuser.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 1000 quiet_success
auth sufficient pam_ldap.so forward_pass
auth required pam_deny.so
account required pam_unix.so broken_shadow
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 1000 quiet
account [default=bad success=ok user_unknown=ignore] pam_ldap.so
account required pam_permit.so
password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password sufficient pam_ldap.so use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
-session optional pam_systemd.so
session optional pam_oddjob_mkhomedir.so umask=0077
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
session optional pam_ldap.so
[root@izanami ~]# cat /etc/nsswitch.conf
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Valid entries include:
#
# nisplus Use NIS+ (NIS version 3)
# nis Use NIS (NIS version 2), also called YP
# dns Use DNS (Domain Name Service)
# files Use the local files
# db Use the local database (.db) files
# compat Use NIS on compat mode
# hesiod Use Hesiod for user lookups
# sss Use sssd (System Security Services Daemon)
# [NOTFOUND=return] Stop searching if not found so far
#
# WARNING: Running nscd with a secondary caching service like sssd may lead to
# unexpected behaviour, especially with how long entries are cached.
# To use db, put the "db" in front of "files" for entries you want to be
# looked up first in the databases
#
# Example:
#passwd: db files nisplus nis
#shadow: db files nisplus nis
#group: db files nisplus nis
passwd: files sss
shadow: files sss
group: files sss
#initgroups: files sss
#hosts: db files nisplus nis dns
hosts: files dns myhostname
# Example - obey only what nisplus tells us...
#services: nisplus [NOTFOUND=return] files
#networks: nisplus [NOTFOUND=return] files
#protocols: nisplus [NOTFOUND=return] files
#rpc: nisplus [NOTFOUND=return] files
#ethers: nisplus [NOTFOUND=return] files
#netmasks: nisplus [NOTFOUND=return] files
bootparams: nisplus [NOTFOUND=return] files
ethers: files
netmasks: files
networks: files
protocols: files
rpc: files
services: files sss
netgroup: files sss
publickey: nisplus
automount: files sss
aliases: files nisplus
「sss」を「ldap」に変更
[root@izanami ~]# cat /etc/nsswitch.conf
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Valid entries include:
#
# nisplus Use NIS+ (NIS version 3)
# nis Use NIS (NIS version 2), also called YP
# dns Use DNS (Domain Name Service)
# files Use the local files
# db Use the local database (.db) files
# compat Use NIS on compat mode
# hesiod Use Hesiod for user lookups
# sss Use sssd (System Security Services Daemon)
# [NOTFOUND=return] Stop searching if not found so far
#
# WARNING: Running nscd with a secondary caching service like sssd may lead to
# unexpected behaviour, especially with how long entries are cached.
# To use db, put the "db" in front of "files" for entries you want to be
# looked up first in the databases
#
# Example:
#passwd: db files nisplus nis
#shadow: db files nisplus nis
#group: db files nisplus nis
passwd: files ldap
shadow: files ldap
group: files ldap
#initgroups: files ldap
#hosts: db files nisplus nis dns
hosts: files dns myhostname
# Example - obey only what nisplus tells us...
#services: nisplus [NOTFOUND=return] files
#networks: nisplus [NOTFOUND=return] files
#protocols: nisplus [NOTFOUND=return] files
#rpc: nisplus [NOTFOUND=return] files
#ethers: nisplus [NOTFOUND=return] files
#netmasks: nisplus [NOTFOUND=return] files
bootparams: nisplus [NOTFOUND=return] files
ethers: files
netmasks: files
networks: files
protocols: files
rpc: files
services: files ldap
netgroup: files ldap
publickey: nisplus
automount: files ldap
aliases: files nisplus
[root@izanami ~]# chkconfig nslcd on
情報:'systemctl enable nslcd.service'へ転送しています。
Created symlink from /etc/systemd/system/multi-user.target.wants/nslcd.service to /usr/lib/systemd/system/nslcd.service.
[user@saya7 ~]$ ssh user@izanami