How to Prevent Raspberry Pi Zero from Blanking or Sleeping
I was setting up a Raspberry Pi Zero in an office to use for displaying a slide show of pictures on a TV in the waiting room and dismayed to learn it would constantly go to sleep after a few minutes. I researched and tried setting the consoleblank=0 in config.txt with no luck along many other solutions, but learned none of them worked for the Raspberry Pi Zero.
sudo apt-get update && sudo apt-get install xscreensaver
I’m not sure why, but I got an error that some dependencies were not installed. If that happens to you as well, run this command in terminal:
sudo apt-get --fix-missing
and then run the install for xscreensaver again
sudo apt-get install xscreensaver
Now under Preferences, you’ll see a new option for screen saver:
On the Display Modes tab, you’ll see a drop down for Mode. Choose “Disable Screen Saver”:
Your raspberry pi zero will now no longer go to sleep.
One-line snippet to update linux and apps on Ubuntu using apt-get
I find myself using this command on Digitalocean droplets fairly often and am sharing in case anyone else finds it useful. Use this one line to install all updates, security fixes, and system upgrades.
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
How to test email sending in Laravel 5.3 using artisan tinker
I’m building a Laravel app and ran into an error when trying to send mail but wasn’t getting an error back since the request was posted through ajax. If you’re trying to troubleshoot it, artisan tinker app is very useful to get more information on the error.
Fire up terminal/command line and run:
php artisan tinker
and then run the following snippet:
\Mail::raw('hello world', function($message) {
$message->subject('Testing email')->to('test@example.org');
});
You should either see a success/null message if everything was correct, or an error with details on what went wrong.
The error I encountered required configuring 2FA in Gmail or you can choose setting the insecure app option up to send through Gmail for testing.
How to repair permissions on Linux Apache /var/www/html folder
I recently ran into an issue where I could no longer FTP files to my Linux droplet when multiple users were uploading to the server. The server kept the user as the owner despite me adding them to the www-data group. This fix comes from my ex-boss, James Tomasino who was kind enough to provide some help since I was stumped. I’m sharing in case anyone else runs into the same issue and finds it useful.
You’ll need to fire up terminal, ssh to the server, and then execute these commands:
cd /var/www sudo chmod 775 html sudo chgrp www-data html sudo chmod g+s html
+s makes permissions sticky so that all files will inherit from the parent directory. This was the setting I was missing.
Open up /etc/ssh/sshd_config. I use nano so:
sudo nano /etc/ssh/sshd_config
Hit CTRL+W and look for “subsystem” which is typically located near the bottom of the file. Change
subsystem sftp /usr/lib/openssh/sftp-server
to
subsystem sftp /usr/lib/openssh/sftp-server -u 0002
If you already have files in the HTML folder, you’ll want to run these commands to reset the permissions:
cd /var/www/ sudo chgrp -R www-data html find . -type f -exec chmod 664 {} \; find . -type d -exec chmod 775 {} \;
How to stop CouchDB on Mac OS
I have been working on a proof of concept using CouchDB. After getting the proof of concept working, I spun up a digital ocean droplet and proceeded to setup CouchDB on the server. I went to enable the SSH tunnel so I could access the CouchDB Futon instance and promptly ran into an error because my local instance of CouchDB was using the same port, 5984. I had a lot of trouble finding out an easy way to stop CouchDB because the documentation in the Wiki wasn’t accurate:
sudo launchctl unload \ /usr/local/Library/LaunchDaemons/org.apache.couchdb.plist
As a workaround, in Terminal, run
launchctl list | grep couchdb
This will output something like:
99093 0 org.apache.couchdb.288008
Grab the highlighted portion and run
launchctl stop "org.apache.couchdb.288008"
Substitute the process name accordingly and you should be able to run the ‘launchctl list’ command again and see the process is no longer present.
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 – error
IÂ recently got handed a new Ubuntu droplet at work to setup and work on. I was going through the typical configuration to lock down the server and go to installing Apache when I suddenly ran into the error
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 – error
I was a little surprised considering I had only run 4 commands total on a brand new installation. If you’re getting this error like me, you’ll need to find out what’s being bound to port 80 and then stop it. Use this command to get a list of anything that’s running on port 80.
sudo lsof -i:80
For me, it turned out nginx was running and bound to port 80. If you have the same problem, run this command to stop it:
sudo service nginx stop
Now you should be able to start apache.
Copy File Context to Clipboard via Command Line, Git Bash (Mingw64), or Terminal
I’ve been spending more time switching from SVN to Git and learning the command line options. I’m finding a lot of the Mac Git terminal commands I run aren’t the same in Git Bash (Mingw64). One of the commands I use is the pbcopy command to copy the ssh key to the clipboard to paste into Github and Bitbucket accounts. I’m starting to use it more as I am learning managing Linux servers and adding my key to login. I’m adding it here as a cheatsheet for myself but I thought others may find it useful.
On Windows, you can run this command to copy your ssh key to the clipboard:
clip < ~/.ssh/id_rsa.pub
On Mac:
pbcopy < ~/.ssh/id_rsa.pub
or if you want to view it in the terminal window:
cat ~/.ssh/id_rsa.pub
How to Copy and Paste into the Digital Ocean VNC Console
I recently signed up for Digital Ocean to test droplets for my development and linux management testing. I was securing the server and setup fail2ban, disabled the root login, and created a user account but forgot to change the user name from root to the user name I selected in my SSH client profile. I ended up locking myself out of the server and had to resort to logging into the admin panel on Digital Ocean’s website and use their browser embedded VNC client to restore my access. I quickly discovered that one of the downsides of using this panel is that you can’t copy and paste commands. Luckily there’s a workaround and you can use the browser console to do sendkeys through Javascript.
Bring up the console in the browser developer tools. Here’s a cheat sheet for keyboard shortcuts:
Browser | Description | Windows | Mac |
---|---|---|---|
Chrome | Open Developer Tools and bring focus to the console | Ctrl + Shift + J | Cmd + Opt + J |
Firefox | Open Console | Ctrl + Shift + K | Cmd + Opt + K |
Internet Explorer | After hitting F12, you have to click the console tab. There’s no direct shortcut to the console tab. | F12 | N/A |
!function(){function t(){window.rfb.sendKey(e.shift().charCodeAt()),e.length>0&&setTimeout(t,10)}var e=prompt("Enter text to be sent to console").split("");t()}();
Update 9-21-16
Ruden and Sebastiaan’s pointed out there was a bug in the code above. This updated snippet has support for characters when using shift characters like !@#$%^&*()_+
!function(){function t(){function n(t,e){s=s.concat(RFB.messages.keyEvent(t,e))}var o=e.shift(),s=[],i=o.charCodeAt(),c=-1!=='!@#$%^&*()_+{}:"<>?~|'.indexOf(o),r=XK_Shift_L;c&&n(r,1),n(i,1),n(i,0),c&&n(r,0),rfb._sock.send(s),e.length>0&&setTimeout(t,10)}var e=prompt("Enter text to be sent to console").split("");t()}();
You’ll receive a dialog prompt to enter the copy to paste in. Please note that you need to click on the VNC console and hit enter to execute the command.
If you need to enter more than one command, just hit the up arrow on your keyboard in the console to get the script again for easy reuse.