This seems like a very basic thing to do, and I have even followed a few tutorials to get a simple script to be run at startup, but to no avail.

Here is what my script, which is in the root directory, looks like:

#! /bin/bash
xmodmap ~/.xmodmaprc
echo 0 | sudo tee /sys/module/hid_apple/parameters/iso_layout

The script basically changes my keymap, by switching control and command keys (as I'm on a macbook). It has been chmod'ed to be executable, so that it executes successfully when I do ./keymap_fix.sh or I do /root/keymap_fix.sh

I have followed these simple tutorials https://www.cyberciti.biz/tips/linux-how-to-run-a-command-when-boots-up.html and https://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/

So, I have copied the shell script to /etc/init.d and did this also update-rc.d keymap_fix.sh defaults 100

I even tried setting up crontab in a similar way, by adding @reboot /root/keymap_fix.sh , but nothing works! Whenever I reboot, my keymap remains the same. :/

Would be grateful if someone could help me out here, thanks!

  • Have you tried to run your script from .bashrc file?
    – mrc02_kr
    Aug 28 '17 at 8:59
  • I've answered the same question in here: unix.stackexchange.com/a/560551/342948 Jan 9 '20 at 21:34
  • @ram0nvaldez you should mark this question as a duplicate of that one
    – roaima
    Jan 9 '20 at 22:36
  • The xmodmap command needs to be run at X11 session startup instead, so that it will be able to communicate with the X server. Cron jobs, startup scripts and systemd system services all run in separate environments that have no connection with the X11 session, and some of them might even run too early, before the X11 server has even started.
    – telcoM
    Apr 28 at 6:36
  • Does this answer your question? start script at boot for kali linux
    – roaima
    Apr 28 at 6:58

Commands like xmodmap can only run in X window,

You should create a dot.desktop file in the xdg autostart folder, e.g create a file ~/.config/autostart/startup.desktop and put these lines in it:


See this link for details


This question is a duplicate of start script at boot for kali linux

I answered that one with these steps:

sudo vim /etc/systemd/system/rc-local.service

Then add the following content to it.

 Description=/etc/rc.local Compatibility

 ExecStart=/etc/rc.local start


Note: Starting with 16.10, Ubuntu doesn’t ship with /etc/rc.local file anymore. Same thing for other distributions like Kali. You can create the file by executing this command.

printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local

Then add execute permission to /etc/rc.local file.

sudo chmod +x /etc/rc.local

After that, enable the service on system boot:

sudo systemctl enable rc-local

Finally, start the service and check its status:

sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

The complete post: How to Enable /etc/rc.local with Systemd.

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.