Sunday 9 August 2009

Toggling keyboards in Xubuntu

I recently switched to Xubuntu from Ubuntu. I wanted to retain the ability to switch from ES to US keyboard by pressing my right control key. For this purpose, I created a new file at /usr/bin called togglekeyboard. The file contains:

#!/bin/bash
setxkbmap -option grp:switch,grp:rctrl_toggle us,es

us and es stand for US and Spanish keyboards. You will better know the id of your desired keyboard flavour.

Then, rctrl_toggle asks setxkbmap to toggle the keyboard on the right-control-key-pressed event. I chose this key as I am not using it for anything else. I got used to press the left control key for all properly controlish purposes. Other options that may suit you are:

  • toggle – right alt key
  • ctrl_shift_toggle – ctrl+shift
  • alt_shift_toggle – alt+shift
  • ctrl_alt_toggle – ctrl+alt
  • caps_toggle – CapsLock
  • lctrl_toggle – left control key
  • switch – switch while the right alt is pressed
  • lwin_switch – switch while the left Windows key is pressed
  • rwin_switch – switch while the right Windows key is pressed
  • win_switch – switch while the any Windows key is pressed

Thursday 6 August 2009

Restricting access to PostgreSQL databases to users

I have created some postgres databases and I want given users to have access only to them (and no others) from any network. For that purpose, in the pg_hba.conf configuration file, under the IPv4 local connections header, I have created the following entries:

host all postgres 0.0.0.0/0 password
host all cjgb 0.0.0.0/0 password

These are the entries that provide unrestricted access to myself (impersonated by either the postgres or the cjgb user) as administrator of the database to connect to "all" databases from "0.0.0.0/0", this is, any host, provided I use the right password.

Access for the other users is restricted as follows:

host varios varios 0.0.0.0/0 password
host postgres varios 0.0.0.0/0 password
host riesgo_desviacion riesgo_desviacion 0.0.0.0/0 password
host postgres riesgo_desviacion 0.0.0.0/0 password

Users varios and riesgo_desviacion can only access tables varios and riesgo_desviacion (respectively) from any network if they provide the right password. I also had to grant them access to the postgres database (for reasons I still have to investigate, but that I am afraid stem from the fact that I mistakenly used the postgres database as template to create the new ones).