Save setxkbmap settings?

35,089

An easy way would be to add the command to your $HOME/.profile file (you can create it if it doesn't exist):

setxkbmap se

That should make it run every time you log in.

Note that you should use $HOME/.profile rather than $HOME/.bash_profile, $HOME/.bashrc or some other similar file. This is because this setting should be read by your login manager.

Share:
35,089

Related videos on Youtube

justanotherhobbyist
Author by

justanotherhobbyist

Updated on September 18, 2022

Comments

  • justanotherhobbyist
    justanotherhobbyist over 1 year

    I'm having trouble setting my keyboard settings to swedish, running Raspbian on a raspberry pi. I've tried everything and the only thing that worked was the command setxkbmap se.

    But this doesn't permanently save the settings, and it's back to default after reboot. Is there a command to permanently save these settings?

  • justanotherhobbyist
    justanotherhobbyist over 10 years
    I have 3 .profile files, located in /home/pi/, /root/ and /etc/skel/. I suppose you're referring to the one in /home/pi/? As you can see I'm not completely comfortable with linux. .bash_profile doesn't exist.
  • justanotherhobbyist
    justanotherhobbyist over 10 years
    Adding setxkbmap se to /home/pi/.profile fixed it. Thanks, you saved me from alot of headache.
  • terdon
    terdon over 10 years
    @hustlerinc the /etc/profile is the global one which will always be read, whichever user is logging on. Each user then has their own personal .profile file in their home folders. So, /root/.profile is root's and /home/pi/.profile is the one for the user pi. I asked about the other files because if $HOME/.bash_profile or $HOME/.bash_login exist those files are read instead of $HOME/.profile. If they don't exist, never mind. For more details, read the INVOCATION section of the man bash or see here.
  • justanotherhobbyist
    justanotherhobbyist over 10 years
    So putting it in /etc/skel/.profile would be better if I have more than 1 user? Or maybe /root/.profile? Which is best?
  • terdon
    terdon over 10 years
    @hustlerinc if you want all users to have that layout, add it to /etc/profile. Adding it to /skel/profile will cause any new user to have the layout set in their personal $HOME/.profile but will not affect existing users.
  • justanotherhobbyist
    justanotherhobbyist over 10 years
    Ok, I have no such file in etc, and creating a new .profile didn't fix it.
  • terdon
    terdon over 10 years
    @hustlerinc The file in /etc should be called profile not .profile (no .). Does that work?
  • justanotherhobbyist
    justanotherhobbyist over 10 years
    Oh, that's why I didn't find it. Problem solved, thanks!
  • Jan Warchoł
    Jan Warchoł over 8 years
    Interestingly, it doesn't work if I put the setting in ~/.bash_profile - it only works when I add it to ~/.profile (at least on Linux Mint 17.1).
  • terdon
    terdon over 8 years
    @JanekWarchoł yes, that's because you are logging in graphically and while some login managers source ~/.profile, to my knowledge, none of them source ~/.bash_profile. It will work in ~/.bash_profile if you log in from the command line (using ssh, for example).
  • Jan Warchoł
    Jan Warchoł over 8 years
    @terdon but does using setxkbmap make sense in a command-line login at all? If I ssh from host A to host B, and I have some xkb settings on host B, they won't matter anyway because my keyboard is controlled by host A. After all, isn't xkb a tool for configuring keyboard in an X environment?
  • terdon
    terdon over 8 years
    @JanekWarchoł yes, it only makes sense in X which is why it should be in .profile and not .bash_profile.
  • Jan Warchoł
    Jan Warchoł over 8 years
    @terdon ok, I have edited the answer to reflect that: unix.stackexchange.com/review/suggested-edits/117339
  • WesternGun
    WesternGun almost 6 years
    What if I want to use it in login password field? I notice that content in $HOME/.profile is not loaded before login. So when I enter password it is still old QWERTY layout.
  • terdon
    terdon almost 6 years
    @WesternGun that's a very different question. As you point out, the .profile is a user-specific setting. You could probably add it in /etc/profile, but that would affect all users. It would be much better to do it by configuring your login manager. But for that, please ask a new question, explaining what operating system you are using, and what login manager.
  • WesternGun
    WesternGun almost 6 years
    OK I have posted another question here.
  • LRDPRDX
    LRDPRDX over 4 years
    Doesn't work in CentOS 7. I try to remap the CAPS to ESC. So I use setxkbmap -option caps:swapescape command. I placed it in .profile but no effect so in .xinitrc. When I placed it in .bashrc it only works with terminal. But I need it when I graphically log in.
  • terdon
    terdon over 4 years
    @LRDPRDX please ask a new question. This will depend on what tool you use to log in, probably.
  • jay.sf
    jay.sf almost 3 years
    That doesn't seem to work (anymore?) on Ubuntu 20.04, I added it to both /etc/profile and home/me/.profile.