Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Every time I setup a new server, I follow a series of steps on each server in order to get updates, set passwd, remove login via root user, customize a familiar environment (bashrc) and secure the server.

Is it possible to do all that using a script? The setup could include:

  1. distro upgrades and updates

    apt-get update

    apt-get upgrade

  2. adding users

    adduser deployer

    adduser deployer sudo

    mkdir /home/deployer/.ssh

    chmod 700 /home/deployer/.ssh

    touch /home/deployer/.ssh/authorization_keys

    deployer passwd

    su deployer

    cd to /home/deployer/.ssh/

    sudo chown deployer .ssh/

  3. Executing commands on local machine:

    ssh-copy-id root@hostname.com

    ssh-copy-id deployer@hostname.com

  4. logging back onto server:

    chmod 400 /home/deployer/.ssh/authorized_keys

    chown deployer:deployer /home/deployer -R

5..6...7.. Customizing bashrc, editing sshd_config, installing ufw & logwatch

share|improve this question
1  
Look up config management systems like puppet or chef. –  SvW Apr 3 '13 at 15:40
    
Or Ansible/Salt, for a different approach. –  ceejayoz Apr 3 '13 at 15:41
1  
have a look at kickstart installation - help.ubuntu.com/lts/installation-guide/i386/… –  Gryphius Apr 3 '13 at 15:44

2 Answers 2

up vote 5 down vote accepted

Use a Kickstart or equivalent process to manage the build. Use a configuration management product like Puppet to deploy your settings.

You can also use a little bit of scripting magic to kick off the configuration management at the end of your build to make it a seamless experience.

My script sets a static IP, configures OSSEC and performs a couple puppet runs to sort out all the dependencies then runs a yum update (I'm primarily a CentOS user).

It's possible to cobble together other methods of getting the same results but I've found this to be the most flexible method I've worked with.

share|improve this answer
2  
Cobbler all the things! –  Scott Pack Apr 3 '13 at 17:07
    
@ScottPack - yeah, I looked Cobbler a while ago. I already Puppet, Kickstart and PXEBoot running for other things. Didn't see a reason to change. Didn't want to comment on a package I don't actively use. –  Tim Brigham Apr 3 '13 at 18:26
    
Yeah, cobbler is nice, but really all it does is templatize your kickstarts so they can be programmatically built on the fly. Not much different from the erb templates in puppet. –  Scott Pack Apr 4 '13 at 12:39

Kickstart/Jumpstart, Chef (including chef-solo), Puppet, Salt, shell-scripts, and higher-level scripting languages can all be used to solve this problem.

Honestly, it looks like you have a decent beginnings of a shell script. Start there, and if complexity ramps up, either iterate or look into a beefier product. Personally I've had good experience with Chef.

The key to automating all-the-things is to start small; you don't have to go whole-hog into automation. Pick one pain-point, and make that better. Pick another, repeat.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.