Category Archives: SysAdmin

How do you add an existing user to the sudoers file?

Are you or one of your users getting the following error when trying to execute a sudo command?

[username] is not in the sudoers file. This incident will be reported

Here is how to fix that problem (*see note). As root type:

echo '[username] ALL=(ALL) ALL' >> /etc/sudoers

Obviously substitute [username] with your actual username.

*NOTE: Not every user on your system should be part of the sudoers group. Be sure you are following best security practices, and practices specific for your systems, before deciding whether to add someone to the sudoers group or not.

Extend Your Linux Disk Space

I was pondering an interesting, and likely fairly common, situation last night so this morning I was up early getting my geek on (aka, playing, testing, and troubleshooting).

If someone has a Linux VM (cloud server or whatever) with a set size but then need to add more space to their system and make it usable, what’s the best way to do that?

The first though was to power down the VM, increase the size of the disk, then tinker inside of Linux to get the space expanded. I didn’t spend much time messing with this because the first few resources I found sounded very risky and painful – multiple reboots, deleting and recreating existing partitions, etc.

My second thought was to add a second disk to the system and then figure if it could be added seamlessly into the existing space. Well, guess what, it can!

So… first an assumption. I’m starting out with a CentOS server (running in VMware, not that it matters) that has a standard /boot mapped but then has the rest of the space in a logical volume currently mapped to /. I won’t be surprised if someone comments to tell me how that isn’t ideal, but hey, that’s how I was already set up and it works perfectly with my disk-expansion solution.

Here’s what my disk system looked like during the installation:

Initial CentOS disk configuration

So you can see that I started out with a 20 GB (20,480 MiB) drive, assigned 500 MB to /boot and the rest set as a logical volume group containing two logical volumes – swap of 2 GB and / with the remaining (almost) 18 GB.

Here’s what it looks like from inside the system:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       18G  3.2G   14G  20% /
tmpfs                 495M  112K  495M   1% /dev/shm
/dev/sda1             485M   33M  427M   8% /boot

While some people might not like this, and perhaps for good reasons, I do like it because it seems to be the most flexible, with all of the space allocation to / I don’t have to worry about the size of /home folders or web content in /var or logs in /var or anything else. The space is available where needed.

Okay, so, I have a 20 GB drive and I want a total of 40 GB. Rather than increasing the size of the current drive I added a second drive from within VMware. The drive was added “hot” (while the VM was live online and running) but the system didn’t recognize the drive until after a reboot.

Once rebooted, the system showed the new drive (via fdisk -l) but it wasn’t in any usable state. I found a few resources online that said to run fdisk in interactive mode for the first step of preparing this new disk. I’m not a fan of interactive mode when using the command line so when possible I try to avoid it. After some research I stumbled on parted command, which allowed me to avoid fdisk in my process.

So, I’m going to just jump straight into it. Note that when I ran fdisk -l the new (unusable) disk showed up as /dev/sdb – you’ll want to double-check your own system to see how it gets assigned before running any of the following commands.

First I needed to create a new partition out of the idle drive that was sitting around unavailable. As mentioned earlier, my drive was showing up as /dev/sdb. Here’s the command I ran:

parted -s -a optimal /dev/sdb mklabel gpt -- mkpart primary ext2 1 -1

I then needed to create a physical volume on that new partition:

pvcreate /dev/sdb1

Next I needed to add the newly created volume to my existing volume group – the name of which (VolGroup) was specified during the install (and is shown in the image above) and is also noted in the df -h output.

vgextend /dev/mapper/VolGroup /dev/sdb1

Okay, now I need to actually extend the volume that I want to have the additional space (in this case, / – which I named “root” in LVM). To know how large to make the new volume, I had to check the existing group to see how much free space it had, and then check the existing volume to see how much space it was taking. I did this by running the two commands below and taking note of the number of extents reported.

lvm vgdisplay|grep 'Free PE'

That showed 5119 free extents in the volume group.

lvdisplay /dev/VolGroup/lv_root | grep 'Current LE'

That showed 4498 extents were currently being used by the “root” volume.

So, 5119 plus 4498 equals 9617 – which is the new size I want the volume to be – essentially telling it to consume all the available space.

lvresize -l 9617 /dev/VolGroup/lv_root

Now that the volume has been extended, the space still doesn’t show. One last step is needed and that is to extend the file system to take up all of the space in the volume:

resize2fs /dev/VolGroup/lv_root

After that last step I ran another df -h and got this output:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       37G  3.2G   32G   9% /
tmpfs                 495M  276K  495M   1% /dev/shm
/dev/sda1             485M   33M  427M   8% /boot

From that output you can see that the / directory that was originally 18 GB above is now 37 GB. Yeah, I know, 37 GB-18 GB doesn’t equal 20 GB. That’s normal though and explainable but beyond the scope of this post. :-)

Happy hosting!

Installing Windows 2012 Server Core plus IIS8

Installing Windows 2012 Server Core plus IIS8 isn’t as hard as you might think. At least it isn’t as hard as I thought!

Server Core can be intimidating to long-time Windows users who expect to see the comfortable familiarity of the Windows desktop (though that has also changed with Server 2012). Rather than a Windows desktop you are presented with a command window and required to make changes through text commands. Hey, what is this – Linux?!? :)

You can relax though. There are actually ways to still manage your server via GUI through the use of various remote tools. That gives the benefit of the smaller footprint and attack surface on your server, but still the ease-of-management that users are use to.

Here’s a great recent post with a few quick steps on getting Windows 2012 Server Core installed (not many steps there – its super-easy) then the command lines needed to install IIS8 and enable it for remote access. Then the few steps required to get connected remotely to manage your server.

http://www.orcsweb.com/blog/jamie-furr/manage-and-install-iis8-on-windows-2012-server-core/

Check it out – it’s likely way easier than you expected!

Happy hosting!

Linking spam sent through shared IIS SMTP server to a user

Microsoft’s IIS SMTP service won’t log usernames even when SMTP-AUTH is enabled and clients are all authenticating. So, what happens if someone starts abusing the SMTP service (or you perhaps have a runaway process performing the abuse)?

Well, it takes a little effort but it is possible to track down the username being used to authenticate to the service. Here’s a post by Jeff Graves of OrcsWeb showing exactly how to track down this information: http://jeffgraves.me/2013/01/08/linking-spam-sent-through-shared-iis-smtp-server-to-a-user/

Creating AD users in bulk with PowerShell

Terri, a support specialist at OrcsWeb who guest posts here on my site, and who has the 2nd most popular post here, wrote up a nice little post about creating Active Directory (AD) users in bulk easily via PowerShell. If you’re interested in user management or PowerShell in general, go check it out:

http://terrid.me/creating-ad-users-in-bulk-with-powershell/

Happy admin’ing! :)

PS: Terri also has some great posts over at OrcsWeb.