Convert a pem file into a rsa private key

When you build a server in AWS one of the last steps is to either acknowledge that you have access to an existing pem file, or to create a new one to use when authenticating to your ec2 server.

If you want to convert that file into an rsa key that you can use in an ssh config file, you can use this handy dandy openssl command string.

openssl rsa -in somefile.pem -out id_rsa

Note: you don’t have to call the output file id_rsa, you will want to make sure that you don’t overwrite an existing id_rsa file.

Copy the id_rsa file to your .ssh directory and make sure to change permissions on the id_rsa key to read only for just your user.

chmod 400 ~/.ssh/id_rsa

Linux Server won’t restart

Not too long ago I ran into a problem where a server with systemd would not shutdown or reboot through normal means.

When executing  sudo shutdown -r now I would get a weird message back as output:

Failed to start Connection timed out
See system logs and 'systemctl status' for details.
Failed to open /dev/initctl: No such device or address
Failed to talk to init daemon.

I’m still not entirely certain what caused the problem and the suggestion of running  systemctl status to troubleshoot simply resulted in the same message being displayed.

However, if you run into this problem and you just need to get your services back up and running you can force a reboot like this:

Try this first:

systemctl --force reboot

If that doesn’t work, which it didn’t for me, add another –force but know that this will unceremoniously kill all running process.

systemctl --force --force reboot

This of course assumes that you can still gain access to the terminal via ssh. This operation is essentially the same as holding down the power button on a physical machine or hitting the reset button on a VM.

According to the man page this can dangerous if you have a process running that is trying to save data so be certain that you want to forcibly kill off every process on your server before running this command. Try it with only a single –force first.

sudo bang bang

So a day or two ago a co-worker mentioned that you can do  sudo !! to execute the last command in your history as root. I had never heard of such a thing! My life has been changed forever!

Here I’ve been hitting the back arrow like a peasant just to put  sudo in front of a previous command.

Please use your new found powers responsibly.