For a Virtual Private Server (VPS) or any other web or other server you should have alerts sent by email for various things. So for example if you automate security updates for an Ubuntu web server you want to be notified if there is some issue with the automatic update.
In order to check and be sure email is setup and working on the sever there is simple command line code to use:
[bash]mail -s Test[/bash]
you then get a prompt to enter
To: [enter the email and press return]
Cc: [press return]
then a blank where you can type in any text you want in the body of the message.
Then you send the message with by pressing CTRL-d
If you don’t receive the email then you can troubleshoot what is going wrong.
A full update of all packages can be done using the follow, remember this may create some issues is one update makes something else you have no longer work properly. You should test to make sure things all work after the updates (for production systems obviously you should test things before [first updating the staging server to make sure the updates don’t cause any problems] and after the updates).
First update the local package index (to find what needs to be upgraded).
An authentication key allows your server to authenticate the computer you are using has the right key and should be granted access. This lets you use the key instead of a username and password when using ssh.
If you don’t already have a key on your local machine (look for a file named id_rsa.pub in your user home directory under the .ssh folder
will get you to the right directory) then you need to generate the key pair. On your desktop machine use:
Next you copy the file to your server. scp ~/.ssh/id_dsa.pub [user]@[server]:.ssh/
Rename the file on the server to authorized_keys2
[bash]mv id_rsa.pub authorized_keys2[/bash]
The key is for to authenticate your computer. But on the ssh login Ubuntu will look in the user folder. So if you also had user2 access to the server and tried to ssh into the server you would not be authenticated because it would look in user2/.ssh for the authorized key file and not find it. You can put the same key in any user folder on your server to have that user also be automatically authenticated.
Two great hosts for Ruby on Rails are Slicehost and Linode. With these hosts you fully manager your virtual private server, installing the operating system, modifying apache (on Ning…), etc.. I use Ubuntu as the operating system and Apache as the web server.
If you are moving a domain from elsewhere it can be wise to reduce the TTL time to say 5 minutes a few days before you make the switch. This is make the change propagate across the internet more quickly.
And DNS entry on your profile (login to your, for example, Linode account)
Add a new file for /etc/apache2/sites-available/your_site_name.com
Host keys are used to security log into remote servers (such as Virtual Private Servers – VPS). With Ubuntu if you are using host keys to sign into servers securely and have asked for strict checking, if you make a change (such as rebuilding your VPS) the host key will change and you cannot login and will get a message like:
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
Please contact your system administrator.
RSA host key for 18.104.22.168 has changed and you have requested strict checking.
Host key verification failed.
if that happens you need to remove your local host key. Then you can sign back in and you will be able to save a new copy of the host key. If you don’t know why the key has changed you should figure that out first as it maybe be an indication of an important security problem. To remove you local key, you can use ssh-keygen -R [ip address of server with the bad key] for example: ssh-keygen -R 22.214.171.124
Then when you try to sign in you will get
The authenticity of host '126.96.36.199 (188.8.131.52)' can't be established.
RSA key fingerprint is ed:...:ea.
Are you sure you want to continue connecting (yes/no)?
And if you know why (such as you made changes to the server) you can say yes and connect and save the new known host key.
add a user: sudo adduser [newuser]
[bash]sudo adduser john[/bash]
then give password, and setup home folder,when prompted
edit the list of super users
change password of a user – sudo passwd [username]
[bash]sudo passwd john[/bash]
to change your password you can just use sudo passwd.
[bash]sudo deluser username[/bash]
This will not delete the home folder (and subfolder) those must be dealt with separately. A new user created with the old user name would have access to those files.
temporarily lock a user account – Simply locking a user account will not prevent a user from logging into your server remotely if they have previously set up RSA public key authentication.
[bash]sudo passwd -l username[/bash]
To unlock the account
[bash]sudo passwd -u username[/bash]
Groups are used in to control permissions (see file permissions) add user to a group
usermod -G [group-name] [username]
[bash]usermod -G basketball john[/bash]
using the -G switch ads the group as a supplemental group. Using -g would make the group that users primary group.
see what groups a user is in
add a new group: groupadd [new_group_name]
If you try [bash]sudo passenger-status[/bash] and get something like
*** ERROR: Cannot query status for Passenger instance 2280:
Connection refused – /tmp/passenger.2280/info/status.socket
Restarting (not reloading) apache [bash]sudo /etc/init.d/apache2 restart[/bash] may fix the problem.
Tools for monitoring performance and troubleshooting Ubuntu VPS web servers
Munin – graphs of system resources over time. Very nice. Can be a bit difficult to setup.
top – system stats
iotop – like top, but for io stats. Install [bash]sudo apt-get install iotop[/bash] Useful setup [bash]iotop -b -o -d 30 -t[/bash] -b (batch – so you can keep a running tally of results) -o (only those processes with io) -d (delay and seconds – how often to print out stats) -t (include time in printout)
vmstat – stats on memory, io, swap, cpu and system. Example: [bash]vmstat 10[/bash] (prints out stats every ten seconds.
[bash]sudo nano /var/log/apache2/error.log[/bash]
Apache web server access log statistics
Webalizer – [bash]sudo apt-get install webalizer[/bash] GeoIP is required for webalizer [bash]sudo apt-get install geoip-bin[/bash] detailed instructions