I created a file ~/.Xmodmap with my mapping commands. I thought that it will be automatically launched after login (and restart) but it's not. So I have to always run after login the command

$ xmodmap .Xmodmap

Is it possible to automatize this process?

thank you


Yes, but exactly how depends on which shell you're using.

In case of bash, edit ~/.bashrc and add a line saying
xmodmap ~/.Xmodmap

If you don't have a ~/.bashrc yet, create one and start it with

if [ -f /etc/bash.bashrc ] ; then
    . /etc/bash.bashrc

xmodmap ~/.Xmodmap

If you're using a different login shell such as tcsh or dash or zsh, you'll need to check its manpage to see what files it reads and executes on startup and add the command there. If you're unsure what login shell you're using, the SHELL environment variable should have been set, and you can check that instead with echo $SHELL .

EDIT: My bad. ~/.xsession is the correct file to add this.

| improve this answer | |
  • Additional question for fellow helpers: Given that not all terminal emulators default to a login shell I recommended .bashrc rather than .bash_profile; if there's a persuasive argument for keeping it restricted to login shells I'd like to hear it. – Shadur Apr 19 '11 at 7:36
  • I'm using bash. Maybe I asked the question bad way. I edited ~/.bashrc as you said and restarted the computer and after restart I had to run xmodmap ~/.Xmodmap manually to have remapped keys. – xralf Apr 19 '11 at 8:12
  • Try adding the line to ~/.bash_profile as well, as ~/.bashrc may not get loaded in a login shell. – Shadur Apr 19 '11 at 9:07
  • This helped. I had to create the file ~/.bash_profile . Should I add all the lines or only the one line with xmodmap ~/.Xmodmap? – xralf Apr 19 '11 at 9:37
  • This worked for a while but stopped working and I had to run it manually again. – xralf Apr 19 '11 at 9:50

I was looking through old questions here just last night for this issue. This post suggests putting the xmodmap ~/.Xmodmap line in ~/.xsessionrc and making sure /etc/X11/xsession.options contains the line allow-user-xsession.

I haven't rebooted since then to test it, however.

| improve this answer | |
  • It works after restart. I will wait for a while yet because Shadur's answer worked after restart too. – xralf Apr 19 '11 at 13:35
  • Now, I restarted and it doesn't work. – xralf Apr 20 '11 at 19:15
  • 1
    Check out Shadur's comments to his answer; the filename may need to be .xinitrc or .xsession instead. – Wolf Apr 20 '11 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.