Tuesday, August 27, 2013

Magic Reboot: When SSH gets stuck

If you ever need to reboot a host, but you cannot SSH in (you have the password, but the session is frozen), you can use the magic reboot method. Here it is:

ssh root@192.168.0.2 "echo b > /proc/sysrq-trigger"

This will tell host 192.168.0.2 to write b to the /proc/sysrq-trigger file. This will cause an immediate reboot of the host.

Using SCP to send a file to another host

If you can SSH into a host, you can use SCP to send a file securely to it. Here's an example:

scp foobar.txt root@192.168.0.2:/var/log

This will send the file foobar.txt to host 192.168.0.2 as user root and save it to the /var/log directory. SCP will prompt you for a password for the root user, of course, but it works like a charm.