Log into your AWS EC2 instance as your own user

Once you have created and stood up your EC2 instance on AWS you will want to create your own user. By default you have to use the “ec2-user” user and you are not allowed to log in as root*. So you create your own…

sudo useradd -m -G wheel seth
passwd seth

Once you have done this and you have setup your keys correctly (Separate post) you will want to log in as your new user you created…but you cant. Until you do this…

cp -r /root/.ssh /home/user
chown -R user /home/user/.ssh

This allowed me to use the keypair.pem file to log in.

Now what you must do is turn on the ability to SSH in with a password. This option is turned off by default in all Linux AMIs.

vi, nano, pico, etc. into the following file with root privileges:

sudo vi /etc/ssh/sshd_config

Set the following to YES

PasswordAuthentication = yes

Finally you must restart SSH

sudo service sshd restart

That’s it. You must still add users with the adduser command and give them passwords with the passwd command for them to be able to login to your AMI.

* – In case you need to login as root you can do it with this… sudo su -

Advertisements

Bootstrapping a Chef Client

Installing Chef as client is a fairly straight forward thing to do after you already have your Chef Server setup. Heres a brief overview of the key steps you will need to take.

First you will need to install Chef Client. You can do that by following this link. This will take you to the Opscode page that helps you figure out what you need and gives you options on how to actually get the chef-client package.
For my case since I am running CentOS 6 I chose Enterprise Linux 6 on a 64-Bit platform. The command that the page gave me to use was:

curl -L https://www.opscode.com/chef/install.sh | bash

From here you log in as your root user and run the command. As a side note I tried this using just my sudo user and it did not work because for some reason it could not create a lock file. Here is what my error looked like:

downloading https://www.opscode.com/chef/metadata?v=&prerelease=false&p=el&pv=6&m=x86_64
 to file /tmp/install.sh.5247/metadata.txt
trying wget...
url https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.10.4-1.el6.x86_64.rpm
md5 3fe6dd8e19301b6c66032496a89097db
sha256 edd5d2bcc174f67e5e5136fd7e5fffd9414c5f4949c68b28055b124185904d9f
downloaded metadata file looks valid...
downloading https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.10.4-1.el6.x86_64.rpm
 to file /tmp/install.sh.5247/chef-11.10.4-1.el6.x86_64.rpm
trying wget...
Checksum compare with sha256sum succeeded.
Installing Chef 
installing with rpm...
warning: /tmp/install.sh.5247/chef-11.10.4-1.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Permission denied)
Installation failed
Please file a bug report at http://tickets.opscode.com
Project: Chef
Component: Packages
Label: Omnibus
Version:
Please detail your operating system type, version and any other relevant details

Once I tried it again as the actual root user everything worked fine.

And now on to the good stuff…

On your master you need to “create the client”

sudo knife bootstrap 192.168.1.151 --sudo -x seth -N "centos-lab-001"

and you will see something like this…

[sudo] password for seth:
Bootstrapping Chef on 192.168.1.151
Enter your password:
192.168.1.151 Starting Chef Client, version 11.6.0
192.168.1.151 Creating a new client identity for centos-lab-001 using the validator key.
192.168.1.151 resolving cookbooks for run list: []
192.168.1.151 Synchronizing Cookbooks:
192.168.1.151 Compiling Cookbooks...
192.168.1.151 [2014-03-20T22:03:29-04:00] WARN: Node centos-lab-001 has an empty run list.
192.168.1.151 Converging 0 resources
192.168.1.151 Chef Client finished, 0 resources updated

Once this has completed you will need to log into either your on Chef server or as I do, my Opscode hosted management page at https://manage.opscode.com/ Once you have connected go to your Node tab at the top and then click Edit next to your new node that you should see here. From here you will see your available recipes on the left and Run List on the right. What you want to do is click and drag a name of a recipe over to the right to your run list. An easy one to test with is NTP which you can get from the Opscode community or on Github. Once you have done this save and open a terminal to your new node.

do:

sudo chef-client

and you should see a bunch of stuff scroll by and then a success message.

This is a VERY brief guide and there are much more detailed  descriptions of this process that can be found out there. Good luck and feel free to ask questions in the comments or tweet me @devopshomelab

Add a new drive to Centos Virtualbox Guest

I run into this a lot and always forget what the steps are…

With the guest powered off you will need to open VBx manager, right click on your guest name that you want to add the drive to and go to SETTINGS.

Click STORAGE and then either click IDE or SATA controller to highlight it. Then you will click the little drive icon next to it. I always choose new disk at the next little pop up. Follow the prompts….
If you get to this step and that icon is ghosted out make sure your guest is powered off. As of right now I dont think there is a way to hot-add a drive in VBx.

I choose VDI and DYNAMICALLY ALLOCATED, give it a name and a size. I ususally go with about 50GB since all of my VMs are for experimental use and I likely wont use that whole amount.

From here thats all you have to do in VBx itself. Next you will want to start up your gest and mount the drive…

Once you get logged in follow these steps…
sudo fdisk -l
Make sure you see your new drive here. It might be listed as something like /dev/sdb Then do the following….

mkdir /mnt/newdisk
mount -t ext3 /dev/sdb1 /mnt/newdisk
cd /mnt/newdisk
df

to mount automatically on boot, add disk to /etc/fstab my /etc/fstb for example, i added last line

LABEL=79d3d2d4 / ext4 defaults,noatime 0 0
LABEL=e21a3e10 /boot ext3 defaults,noatime 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
/dev/sdb1 /mnt/newdisk ext3 defaults 0 0