• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

CentOS/Fedora/REL Setup - Cloud Servers


This CentOS article will take you from a 'barebones' CentOS Server to a secured and up to date Server ready for your software (or whatever you use the Server for).

Contents

//

Log in

Windows Clients

If you are logging into your server from Windows you can use a terminal application called PuTTY. Simply do a Google search for it and you will find where to download it.

Mac / Linux Clients

Simply type in the command below from a Terminal window to login:

# ssh root@12.34.56.78

If this is a reinstall you may have to delete your ~/.ssh/known_hosts file. Please refer to your Operating Systems documentation on how to resolve this.

User administration

Now we're logged in to the VPS, immediately change your root password

# passwd

Add an admin user (I've used the name demo here but any name will do).

# adduser demo

You will need to specifically set the password for your new user:

# passwd demo

As you know we never log in as the root user (this initial setup is the only time you would need to log in as root). As such, the main administration user (demo) needs to have sudo (Super User) privileges so he can, with a password, complete administrative tasks.

Sudo permissions

To do this we're going to add the main user to the 'wheel' group. Once that is done, we need to edit the 'sudoers' file, using visudo, and ensure the 'wheel' group has the correct privileges.

So firstly, add the user to the wheel group:

# usermod -a -G wheel demo

Next, give the 'visudo' command:

# visudo 

The visudo command runs a default editor and will check the configuration for any syntax errors before saving it.

We'll usually refer you to 'nano' for editing text files.  It's a pretty easy-to-use text editor with nice features like an on-screen tip telling you how to bring up a helpfile. For security reasons, however, visudo on CentOS, Fedora, and RHEL will only use 'vi'.

If you're new to Linux, or have never used the 'vi' editor before, then this part will be a little weird. While vi is a powerful editor once you've learned it, 'user friendly' is definitely not on its list of features. We'll just describe the keystrokes you'll use to make one change here, and talk a little more about vi after.

So with all that said, use the arrow keys to move the cursor down near the bottom of the file.  Look for this entry:

## Allows people in group wheel to run all commands
# %wheel  ALL=(ALL)       ALL

Now we'll uncomment that second line.  Do that by removing the "#" before "%wheel" by moving the cursor to it and typing "x".  Now the line should look like this:

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL

Type ":wq" and "enter", and members of the 'wheel' group will have full sudo privileges.

A little more (optional) vi

If you want to make more changes to this file later you'll want to use more vi than just what we did above.  It can be handy to look for an introduction to vi through a web search - there are a good number of them out there.  Since vi (or vim) is installed on just about any Unix system anywhere it can be a useful editor to learn.

To get you started, some basic vi commands are:

  • Use the arrow keys to move around
  • Hit "i" to start typing inside a line
  • Hit "a" when your cursor is at the end of a line to add to it
  • Hit "escape" to get out of edit mode
  • Hit "x" to delete the character under the cursor
  • Hit "dd" to delete the line of text under the cursor
  • Type ":wq" then "enter" to save your changes and quit
  • Type ":q!" then "enter" to quit without saving any changes
  • When you just can't figure out what it's doing, hit "escape" a couple times, then type ":q!" and "enter" so you can quit and then start over fresh.

Now let's get back to setting up your server.

Yum repositories

The CentOS Server comes with a basic set of repositories that are defined in /etc/yum.repos.d.

Have a look at the enabled repositories, using that more friendly editor, nano:

# nano /etc/yum.repos.d/CentOS-Base.repo

As you scroll through the file you will see each repository has a set of definitions including which mirror to use and what GPG key to use (and actually whether to check the package signature at all).

You can, of course, add more repositories whenever you want to but I would just give a word of caution: Some of the available repositories are not officially supported and may not receive any security updates should a flaw be discovered.

Keep in mind it is a server we are building and not a desktop.

Need a key install?

You may be asked to install a key for the repository. To do this, run the following command:

sudo rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

Update

Now we can update the package list that yum uses.

The command will also offer to install any updated packages. As with all installs have a careful look at the list and, once happy, press 'y' to continue:

# yum update

That's really the basics done for the Server.



© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER

12 Comments

In visudo, after editing wheel, there is no info on how to save & exit??? So for someone new to Linux "Like Me"... it took me a good sec to figure it out. Anyways here you go... (Save & Quit visudo - hit :wq)

An excellent point, Joel. We'll try to get a note added soon about some basic vi usage. It's a powerful editor (which is why CentOS forces it as the editor for visudo), but it's definitely not intuitive for a new user.

Use insert on your keyboard to insert text, then escape, to write the file ":w" to exit ":q"

You can use vim commands in visudo or before falling into visudo, edit $EDITOR variable and set it to nano, in Ubuntu it has now to run nano by default. If you are in not that friendly vim - use this command reference: http://www.tuxfiles.org/linuxhelp/vimcheat.html

On CentOS/Fedora/RHEL, last I checked, you can't actually change the editor visudo uses with the EDITOR environment variable. There's a flag that's set at compile-time for visudo, and unless they changed it recently, the Red Hat folks don't enable it. That forces vim as the editor in visudo.

Ubuntu does, as I recall, allow the use of EDITOR to change the editor for visudo.

Good article! It wouls be helpful if there were alternate CSS for printing that ignores the header and sidebar. Thanks.

Hi Jerry,
That's a terrific idea! We will submit that request, and hopefully this is something you should see added to the site shortly.

To change from VI to the much easier to operate "Nano" editor use this command as root:

export EDITOR=/usr/bin/nano

or as a wheel user:
sudo export EDITOR=/usr/bin/nano

If you really want to use nano for your editor; most, if not all, config files will require the -w switch to not truncate lines at a specific length.

If, like me, you actually prefer vim over nano it can be installed like so:

In CentOS with:
yum install vim-enhanced
or in Ubuntu/Debian with:
apt-get install vim-tiny
or in Gentoo with:
emerge vim

Remember to use sudo if necessary.

I am sorry but I am a bit lost with this instruction:

So with all that said, use the arrow keys to move the cursor down near the bottom of the file. Look for this entry:
## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL

How do I find this file? The instruction before this one is:

Next, give the 'visudo' command:
# visudo

After following these instructions nothing happens. Please help

The "visudo" command should be what brings the file up for editing. If that isn't working, try running "/usr/sbin/visudo" instead, and let us know if that doesn't do anything either.

Nice instructions

Add new comment