In order to logout from a terminal or a console, you can try to set the TMOUT variable. This is valid for both BASH and KSH with a slightly different behaviour (I don't know for other shells). For example, if you want to set a timeout of 15 minutes for all the users, you can add the following to /etc/profile:
For the X environment there are methods which strictly depend on the specific desktop manager in use.