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 |
//
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.
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.
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.
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.
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:
Now let's get back to setting up your server.
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.
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
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

12 Comments
CentOS Setup / "VIsudo"
Re: vi
Use insert on your keyboard
This is vim
Re: visudo
Ubuntu does, as I recall, allow the use of EDITOR to change the editor for visudo.
Suggestion
RE: Suggestion
That's a terrific idea! We will submit that request, and hopefully this is something you should see added to the site shortly.
Changing the default editor in CentOS to NANO
export EDITOR=/usr/bin/nano
or as a wheel user:
sudo export EDITOR=/usr/bin/nano
Vim/Nano infromation
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
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
Re: visudo
Nice instructions
Add new comment