RightScale RightScript To Add SSH Users To Linux Nodes On Boot

The below code snippet was used to add SSH users to RackSpace cloud CentOS Linux nodes being used as application servers and managed via RightScale. The SSH users were required during a testing phase so they could look through logs and make modifications to specific configuration files, etc. There are three things that have to happen to create the SSH user, allow them to login, and provide them the necessary rights on the server to accomplish their tasks which include adding the user, modifying the sshd config to allow password logins, and update the sudoers file to enable sudo access for wheel group users.

RightScript Used To Add SSH Users During Linux Instance Boot Process:


  1. #!/bin/bash -e
  3. # add user
  4. useradd -m -p $SSH_USER_PASS1 $SSH_USER1 -g wheel
  6. # add second user
  7. useradd -m -p $SSH_USER_PASS2 $SSH_USER2 -g wheel
  9. # modify sshd_config to allow password logins
  10. /bin/sed -ie "s/PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config
  12. # restart sshd
  13. /etc/init.d/sshd restart
  15. # modify sudoers to allow members of wheel group to sudo
  16. /bin/sed -ie "s/# %wheel\tALL=(ALL)\tALL/%wheel\tALL=(ALL)\tALL/g" /etc/sudoers

The above script actually adds two users so that portion of the script can easily be modified for more or less SSH users. The variables, which include $SSH_USER1, $SSH_USER_PASS1, $SSH_USER2, and $SSH_USER_PASS2, will be required inputs for the ServerTemplate that the RightScript is applied to. Also not that the \t in the sudoers configuration file modification line represents a tab as explained in this article that was previously written on QD. This script should work for multiple Cloud providers and multiple ServerTemplates representing multiple Linux distributions.

Middleware and Cloud Computing: Oracle on Amazon Web Services (AWS), Rackspace Cloud and RightScale (Volume 1) (Paperback)

List Price: $49.85 USD
New From: $32.00 USD In Stock
Used from: $2.09 USD In Stock