특정 Host에서만 RootLogin 허용

2759 단어 SSHchef

Goal


* chefリポジトリサーバを作成し、knife soloで実行できるようにしたい
* chef soloの実行ユーザは各サーバのrootユーザとしたい
* 各サーバのrootログインをchefリポジトリサーバのみに絞りたい
* 前提として、VPN環境は持っておらず、さくらVPSやAmazon EC2など様々なサービスでサーバを運用していて、さらに様々な場所でwifiを切り替えてそれらサーバを管理している

Plan






* chefリポジトリサーバにnomaduserを作成
 (自分自身以外すべてのサーバにrootログインできる権限を持つ最強ユーザ.遊牧民のようにいろんなサーバを渡り歩くことを仕事とするのでnomadと名づけた.)
* nomaduserのpublic keyを全サーバのrootユーザに配り、sshd_config設定でchefリポジトリのIPアドレスのみPermitRootLoginを許可する
* これで、通常ユーザは通常通りssh鍵認証でログイン可能になり、なんらかの理由で何者かがnomaduserのprivate keyを手に入れても、chefリポジトリサーバ上からしかsshすることはできない
* chefリポジトリサーバのnomaduserは厳重管理する必要がある
* この方法でchefリポジトリサーバを踏み台サーバとすることもできるはず

Manual



sshd_config


PermitRootLogin no
PasswordAuthentication no

## ...

# Permit root ssh login for only chef admin servers
Match Address <chefリポジトリサーバIPアドレス(ssh接続元)>
    PermitRootLogin yes
/etc/init.d/sshd restart

※ Match 명령으로 예외를 만들 수 있는 항목 일람
h tp // w w. 음, r. 오 rg / ~ 에 s 케 / 드 c / 오페 sh / j 만 / shd_ コンフ ぃ g. HTML

모든 설정 항목에 매치 명령이 적용되는 것은 아닙니다.使用できる項目は、AcceptEnv ,AllowAgentForwarding ,AllowGroups ,AllowTcpForwarding ,AllowUsers ,AuthenticationMethods ,AuthorizedKeysCommand ,AuthorizedKeysCommandUser ,AuthorizedKeysFile ,AuthorizedPrincipalsFile ,Banner ,ChrootDirectory ,DenyGroups ,DenyUsers ,ForceCommand ,GatewayPorts ,GSSAPIAuthentication ,HostbasedAuthentication ,HostbasedUsesNameFromPacketOnly ,KbdInteractiveAuthentication ,KerberosAuthentication ,MaxAuthTries ,MaxSessions ,PasswordAuthentication ,PermitEmptyPasswords ,PermitOpen ,PermitRootLogin ,PermitTTY ,PermitTunnel ,PubkeyAuthentication ,RekeyLimit ,RhostsRSAAuthentication ,RSAAuthentication ,X11DisplayOffset ,X

공개 키 공유


## root user of chef target server

echo "<public key of nomaduser>" >> ~/.ssh/authorized_keys

Alternatives



발판 서버를 만들면 iptables, hosts.allow/hosts.deny 등으로 ACL을 걸 수도 있습니다
sshd_config의 "PermitRootLogin forced-commands-only"라고 하면, 리모트 커멘드 실행 모드로만 root ssh 가능하게 되는 것 같지만, 이것이라면 knife solo는 실행할 수 없었다

좋은 웹페이지 즐겨찾기