Setting up a USB Bitcoin miner using cgminer on Ubuntu

By: ( +David Herron; Date: November 4, 2017

Tags: Bitcoin Mining

Looking at the ever-increasing Bitcoin price and wondering how to get in on the action? One way to dip a toe in the water is to buy a cheap older-model Bitcoin miner, such as the Bitmain Antminer U3. These run around $100 on eBay currently and are a proper ASIC-based Bitcoin miner with very low power consumption. It connects to your computer via USB, and requires software like cgminer to connect to a mining pool. Other USB based Bitcoin miners exist, and while the following instructions are for the Antminer U3, the process should be similar for any other USB Bitcoin miner.

You may already know this - but a little basic preview. Bitcoins are "mined" by a distributed computation process. Chunks of data is distributed over the Internet to mining hardware. The mining hardware runs the computations to prove a new block on the Bitcoin Blockchain. The hardware that successfully completes this computational task wins that block of Bitcoin, and then the Bitcoin network silently moves on to computing the next coin.

Since it's completely impractical for an individual bitcoin mining hardware to compete in the current mining landscape it's necessary to connect your hardware to a mining pool. Several mining pools exist, and in this case we'll use the Slushpool.

For a list of pools see: (

To sign up with Slushpool, go to ( and go through the signup process.

Their help center has a beginners guide that's useful. One thing to note is their warning that ASIC Miners are the only way to go in the current Bitcoin mining landscape. That's because the computational difficulty has grown to where a CPU is simply unable to do the TeraHashes/Second that is now typical.

Configuration parameters

The mining pool you choose may have different policies than this. What you'll need is three items of configuration to connect your mining hardware to the mining pool.

  • URL that's to be used to connect with the mining pool -- such as stratum+tcp://
  • The username for your account with the mining pool -- such as reikiman
  • The worker name for the particular piece of hardware -- such as worker1
  • THe password to use in the connection

I lied, that's four pieces of configuration. Slushpool doesn't care what password you use. If you like, feel free to connect to Slushpool using my username. There's no password, and your hardware will connect and start computing hashes. But you will not get any economic benefit, I will. Please, feel free to connect your hardware to my account. I won't stop you.

The next configuration is to set up a payment address. This is a Bitcoin address for your wallet. That address is provided by your wallet provider.

The address might look like 1MKQ2HaCU6SPT4aYqEv8tKeYpXdgjjanzG -- Feel free to use that address if you like, since that's my wallet.

For now just record these parameters somewhere. For the wallet address, go to the Settings area of the mining pool and enter the address in the appropriate place.


If you want to install cgminer from source, go here: (

On x86 Ubuntu you can install it from the package manager

$ apt-cache search cgminer
cgminer - multi-threaded multi-pool Bitcoin miner
$ sudo apt-get install cgminer

THe cgminer version available that way is modern enough to support the Antminer U3 out of the box. It may be that your Bitcoin miner isn't supported with the pre-built binary for Ubuntu, and you'll instead have to compile from source. If so, go through the instructions in the Github repository.

I tried setting this up using ARM-based Linux Single Board Computers (e.g. Raspberry Pi) but did not have success. With the Debian version on the the hardware I tried (the C.H.I.P. and the Orange Pi Zero2) the cgminer version did not support the Antminer U3. I tried compiling from source with no luck.

The problem with using cgminer is that it's a CURSES based application and it doesn't fit well as a background process. But we want it to run 24 hours a day, dictating that it be a background process.

cgminer in the background using screen

Fortunately there's a screwball way to proceed that's kind of ingenuous. The screen application is normally meant to interactively to maintain multiple terminal sessions in one terminal window.

Let's start with this command:

screen -LdmS cgminer /usr/bin/cgminer --config /home/david/cgminer.conf

The options are:

  • -L turns on logging of output in each window
  • -d -m Starts the screen process in detached mode, creating a new session without attaching to it. This is great for system-level startup scripts like what we'll do in a minute.
  • -S cgminer sets the session name

The rest is a command-line to run, namely the cgminer command pointing to a configuration file.

$ cat cgminer.conf
"pools" : [
                 "url" : "stratum+tcp://",
                "user" : "reikiman.worker1",
                "pass" : "anything-at-all"
       "api-listen" : true,
       "api-port" : "4028",
       "expiry" : "120",
       "failover-only" : true,
       "log" : "5",
       "no-pool-disable" : true,
       "queue" : "2",
       "scan-time" : "60",
       "worktime" : true,
       "shares" : "0",
       "kernel-path" : "/usr/local/bin",
       "api-allow" : "0/0",
       "icarus-options" : "115200:1:1",
       "icarus-timing" : "3.0=100"

Here's where you configure the pool configuration. Again, feel free to connect your hardware to my account, I won't mind ;-)

If running this manually from the command-line, use sudo as so:

sudo screen -LdmS cgminer /usr/bin/cgminer --config /home/david/cgminer.conf

Once you've run this, you can connect to the screen session as so:

screen -d -r cgminer

The display may look like what's in the image at the top of this posting. If your configuration is correct, cgminer will connect to the mining pool and start retrieving blocks. The other parts of the display will start showing a hashing rate, and information about each block will be printed as the blocks are processed.

The hash rate is shown here:

(5s):18.29G (1m):14.36G (5m):14.32G (15m):14.31G (avg):16.14Gh/s

And your status is shown on the next couple of lines.

Once you're done browsing the cgminer output, symply type Control-A d to exit the screen session. You can re-run screen -d -r cgminer to hop back into the session to see that you can attach and detach whenever you like.

Making a background service

The above is fine and will keep the cgminer process running -- until the system reboots. This does not automatically restart the cgminer process on rebooting the system. To do so, we need to write a script that manages a background service.

While we could make an LSB-compliant init script in /etc/init.d let's instead create a service.

Create this file: /lib/systemd/system/cgminer.service


# Type=simple

# screen -dm creates detached session that forks.
#  use this with Type=forking
ExecStart=/usr/bin/screen -LdmS cgminer /usr/bin/cgminer --config /home/david/cgminer.conf
# screen -Dm creates detached session that doesn't fork.
#  use this with Type=simple
# ExecStart=/usr/bin/screen -LDmS cgminer /usr/bin/cgminer --config /home/david/cgminer.conf

# tell cgminer to quit (not screen), and screen will exit
ExecStop=/usr/bin/screen -S cgminer -X stuff 'q'

# or tell screen to quit and clobber cgminer - not best choice
#ExecStop=/usr/bin/screen -S cgminer -X quit
#Probably need a kill definition in case the miner is hung

# sending the string 'scy' (settings, restart, yes) to cgminer will
#  cause a restart which will re-read config file if using one
ExecReload=/usr/bin/screen -S cgminer -X stuff 'scy'


This has two options - Forking and Non-Forking. You'll see that Forking mode is done with the -LdmS option string, while Non-Forking is done with -LDmS. The service description has commands to Start, Stop and Reload the service, and the commands in each case do the correct thing.

Next you initialize and start the service.

sudo systemctl daemon-reload
sudo systemctl enable cgminer.service
sudo systemctl start cgminer.service

And finally, this lets you verify the service is running:

sudo systemctl status cgminer.service

This command can be useful for examining the startup of the process in case it doesn't start as expected.

sudo journalctl -xe

The next thing to try is connecting to the cgminer session:

screen -d -r cgminer

This is exactly the same as before, but the cgminer session is started automatically when the system reboots. If you want to test that, restart the system.

You may need to manually stop and restart the background service. For example, to debug the configuration and ensure it's starting correctly.

sudo systemctl stop cgminer.service
sudo systemctl start cgminer.service
« Social media networks don't spread propaganda, people spread propaganda (through social media networks) Facebook et al admits to large-scale Russian advertising campaigns, illegal political advertising by foreigners »
2016 Election 2018 Elections Acer C720 Ad block Air Filters Air Quality Air Quality Monitoring AkashaCMS Amazon Amazon Kindle Amazon Web Services America Amiga and Jon Pertwee Android Anti-Fascism AntiVirus Software Apple Apple Hardware History Apple iPhone Apple iPhone Hardware April 1st Arduino ARM Compilation Artificial Intelligence Astronomy Astrophotography Asynchronous Programming Authoritarianism Automated Social Posting AWS DynamoDB AWS Lambda Ayo.JS Bells Law Big Brother Big Data Big Finish Big Science Bitcoin Mining Black Holes Blade Runner Blockchain Blogger Blogging Books Botnets Cassette Tapes Cellphones China China Manufacturing Christopher Eccleston Chrome Chrome Apps Chromebook Chromebox ChromeOS CIA CitiCards Citizen Journalism Civil Liberties Climate Change Clinton Cluster Computing Command Line Tools Comment Systems Computer Accessories Computer Hardware Computer Repair Computers Conservatives Cross Compilation Crouton Cryptocurrency Curiosity Rover Currencies Cyber Security Cybermen Cybersecurity Daleks Darth Vader Data backup Data Formats Data Storage Database Database Backup Databases David Tenant DDoS Botnet Department of Defense Department of Justice Detect Adblocker Developers Editors Digital Nomad Digital Photography Diskless Booting Disqus DIY DIY Repair DNP3 Do it yourself Docker Docker MAMP Docker Swarm Doctor Who Doctor Who Paradox Doctor Who Review Drobo Drupal Drupal Themes DVD E-Books E-Readers Early Computers eGPU Election Hacks Electric Bicycles Electric Vehicles Electron Eliminating Jobs for Human Emdebian Encabulators Energy Efficiency Enterprise Node EPUB ESP8266 Ethical Curation Eurovision Event Driven Asynchronous Express Face Recognition Facebook Fake News Fedora VirtualBox Fifth Doctor File transfer without iTunes FireFly Flash Flickr Fraud Freedom of Speech Front-end Development G Suite Gallifrey Gig Economy git Github GitKraken Gitlab GMAIL Google Google Chrome Google Gnome Google+ Government Spying Great Britain Green Transportation Hate Speech Heat Loss Hibernate High Technology Hoax Science Home Automation HTTP Security HTTPS Human ID I2C Protocol Image Analysis Image Conversion Image Processing ImageMagick In-memory Computing InfluxDB Infrared Thermometers Insulation Internet Internet Advertising Internet Law Internet of Things Internet Policy Internet Privacy iOS iOS Devices iPad iPhone iPhone hacking Iron Man iShowU Audio Capture iTunes Janet Fielding Java JavaFX JavaScript JavaScript Injection JDBC John Simms Journalism Joyent Kaspersky Labs Kext Kindle Kindle Marketplace Large Hadron Collider Lets Encrypt LibreOffice Linux Linux Hints Linux Single Board Computers Logging Mac Mini Mac OS Mac OS X MacBook Pro Machine Learning Machine Readable ID Macintosh macOS macOS High Sierra macOS Kext MacOS X setup Make Money Online Make Money with Gigs March For Our Lives MariaDB Mars Mass Violence Matt Lucas MEADS Anti-Missile Mercurial MERN Stack Michele Gomez Micro Apartments Microsoft Military AI Military Hardware Minification Minimized CSS Minimized HTML Minimized JavaScript Missy Mobile Applications Mobile Computers MODBUS Mondas Monetary System MongoDB Mongoose Monty Python MQTT Music Player Music Streaming MySQL NanoPi Nardole NASA Net Neutrality Network Attached Storage Node Web Development Node.js Node.js Database Node.js Performance Node.js Testing Node.JS Web Development Node.x North Korea npm NVIDIA NY Times Online advertising Online Community Online Fraud Online Journalism Online Photography Online Video Open Media Vault Open Source Open Source and Patents Open Source Governance Open Source Licenses Open Source Software OpenAPI OpenJDK OpenVPN Palmtop PDA Patrick Troughton PayPal Paywalls Personal Flight Peter Capaldi Peter Davison Phishing Photography PHP Plex Plex Media Server Political Protest Politics Postal Service Power Control President Trump Privacy Private E-mail server Production use Public Violence Raspberry Pi Raspberry Pi 3 Raspberry Pi Zero ReactJS Recaptcha Recycling Refurbished Computers Remote Desktop Removable Storage Republicans Retro Computing Retro-Technology Reviews RFID Rich Internet Applications Right to Repair River Song Robotics Robots Rocket Ships RSS News Readers rsync Russia Russia Troll Factory Russian Hacking Rust SCADA Scheme Science Fiction SD Cards Search Engine Ranking Season 1 Season 10 Season 11 Security Security Cameras Server-side JavaScript Serverless Framework Servers Shell Scripts Silence Simsimi Skype SmugMug Social Media Social Media Networks Social Media Warfare Social Network Management Social Networks Software Development Software Patents Space Flight Space Ship Reuse Space Ships SpaceX Spear Phishing Spring Spring Boot Spy Satellites SQLite3 SSD Drives SSD upgrade SSH SSH Key SSL Stand For Truth Strange Parts Swagger Synchronizing Files Tegan Jovanka Telescopes Terrorism The Cybermen The Daleks The Master Time-Series Database Tom Baker Torchwood Total Information Awareness Trump Trump Administration Trump Campaign Twitter Ubuntu Udemy UDOO US Department of Defense Video editing Virtual Private Networks VirtualBox VLC VNC VOIP Vue.js Walmart Weapons Systems Web Applications Web Developer Resources Web Development Web Development Tools Web Marketing Webpack Website Advertising Weeping Angels WhatsApp William Hartnell Window Insulation Windows Windows Alternatives Wordpress World Wide Web Yahoo YouTube YouTube Monetization