前面对puppet有了一个简单的了解,要想快速掌握还得拉出来练练,所以先写一个安装兼配置SSH的模块。
在/etc/puppet/modules目录下创建ssh模块目录,结构如下:
ssh ├── files ├── manifests │ ├── config.pp │ ├── init.pp │ ├── install.pp │ └── service.pp └── templates └── sshd_config.erb
1 配置install.pp文件:
#install.pp class ssh::install { package { "openssh-server": ensure => present, } }
2 配置config.pp文件:
#config.pp class ssh::config { File { owner => root, group => root, mode => 0644, } file { "/etc/ssh/sshd_config": ensure => present, content => template("ssh/sshd_config.erb"), require => Class["ssh::install"], notify => Class["ssh::service"], } }
4 配置ssh_config.erb文件:
#################################### #only use Protocol 2 #only use port 26000 #bind address #################################### Protocol 2 Port 26000 ListenAddress <%= ipaddress %> #################################### # forbid kerbero auth #################################### kerberosauthentication no kerberosorlocalpasswd no kerberosticketcleanup yes #################################### #forbid ResponseAuth (s/key) #################################### ChallengeResponseAuthentication no #################################### #forbid GSSAPI auth #################################### GSSAPIAuthentication no GSSAPICleanupCredentials yes #################################### #forbid Pubkey auth #################################### PubkeyAuthentication no AuthorizedKeysFile .ssh/authorized_keys #################################### #forbid host auth #################################### HostbasedAuthentication no IgnoreUserKnownHosts yes IgnoreRhosts yes #################################### #use unix/passwd auth #################################### PasswordAuthentication yes #################################### #shutdown X11 forward # #shutdown tcp forward #################################### X11Forwarding no GatewayPorts no AllowTcpForwarding no #################################### #log level VERBOSE #log Facility AUTH #################################### LogLevel VERBOSE SyslogFacility AUTH #################################### #forbid ssh client trans var #################################### AcceptEnv none #################################### # forbid system user login #################################### AllowUsers * DenyUsers daemon bin sys sync games man lp mail news uucp proxy www-data backup list irc gnats nobody Debian-exim statd identd sshd libuuid snmp #################################### #use welcome info # #don't show path info # #################################### Banner /etc/issue PrintMotd no PrintLastLog no #################################### #design encrypt algorithm # #################################### ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbc macs hmac-md5,hmac-sha1,hmac-ripemd160,hmac-sha1-96,hmac-md5-96 #################################### #per 300s check client alive #timeout 2 #forbid tcpkeepalive #################################### clientaliveinterval 300 clientalivecountmax 2 tcpkeepalive no #################################### #1000 times connetc auth #must auth in 20s #max times 3 #################################### MaxStartups 1000 LoginGraceTime 20 MaxAuthTries 3 #################################### #support compress #forbid dns #use pam mod #################################### Compression yes UseDNS no UsePAM yes #################################### #if other user have read authorized.keys #then forbin connect #don't have root premit login #don't use null login pass #################################### strictmodes yes PermitRootLogin no PermitEmptyPasswords no UsePrivilegeSeparation yes UseLogin no #################################### #suport sftp #################################### Subsystem sftp /usr/lib/openssh/sftp-server #################################### #ssh pidfile #################################### PidFile /var/run/sshd.pid #################################### #host key location #################################### HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_dsa_key
5 配置service.pp文件:
#service.pp class ssh::service { service {"ssh": ensure => running, hasstatus => true, hasrestart => true, enable => true, require => Class["ssh::config"], } }
6 配置init.pp文件:
#init.pp class ssh { include ssh::install,ssh::config,ssh::service }