├── provider.tf ├── outputs.tf ├── images ├── ec2.png ├── pool.png ├── xmr.png └── cpu_usage.png ├── vars.tf ├── .gitignore ├── license ├── main.tf ├── .terraform.lock.hcl ├── README.md └── xmrig └── run-xmrig.sh /provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = var.region 3 | } -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | output "xmr_miners" { 2 | value = aws_instance.xmr-miner.*.arn 3 | } -------------------------------------------------------------------------------- /images/ec2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R3DRUN3/aws-monero-mining/HEAD/images/ec2.png -------------------------------------------------------------------------------- /images/pool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R3DRUN3/aws-monero-mining/HEAD/images/pool.png -------------------------------------------------------------------------------- /images/xmr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R3DRUN3/aws-monero-mining/HEAD/images/xmr.png -------------------------------------------------------------------------------- /images/cpu_usage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R3DRUN3/aws-monero-mining/HEAD/images/cpu_usage.png -------------------------------------------------------------------------------- /vars.tf: -------------------------------------------------------------------------------- 1 | 2 | variable "ec2_ami" { 3 | type = map 4 | 5 | default = { 6 | # change ami here if you want 7 | eu-central-1 = "ami-0caef02b518350c8b" 8 | } 9 | } 10 | 11 | # Change default region here if you want 12 | 13 | variable "region" { 14 | default = "eu-central-1" 15 | } 16 | 17 | 18 | # Creating a Variable for instance_type 19 | variable "instance_type" { 20 | type = string 21 | } 22 | 23 | variable "instance_count" { 24 | # change the number of instances here 25 | default = "2" 26 | } 27 | 28 | variable "ip_list" { 29 | description = "Allowed IPs" 30 | type = list(string) 31 | default = [ 32 | "0.0.0.0/0", 33 | ] 34 | } 35 | 36 | variable "port_list" { 37 | description = "Allowed ports" 38 | type = list(number) 39 | default = [ 40 | 22, # only allow ssh connection 41 | ] 42 | } 43 | 44 | variable "sec_group_name" { 45 | default = "XMR Miners" 46 | } 47 | 48 | variable "sec_group_description" { 49 | default = "XMR Miners Security Group" 50 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | crash.*.log 11 | 12 | # Exclude all .tfvars files, which are likely to contain sensitive data, such as 13 | # password, private keys, and other secrets. These should not be part of version 14 | # control as they are data points which are potentially sensitive and subject 15 | # to change depending on the environment. 16 | *.tfvars 17 | *.tfvars.json 18 | 19 | # Ignore override files as they are usually used to override resources locally and so 20 | # are not checked in 21 | override.tf 22 | override.tf.json 23 | *_override.tf 24 | *_override.tf.json 25 | 26 | # Include override files you do wish to add to version control using negated pattern 27 | # !example_override.tf 28 | 29 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 30 | # example: *tfplan* 31 | 32 | # Ignore CLI configuration files 33 | .terraformrc 34 | terraform.rc -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 R3DRUN3 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_instance" "xmr-miner" { 2 | # Creates n identical aws ec2 instances for xmr mining 3 | count = var.instance_count 4 | 5 | ami = lookup(var.ec2_ami,var.region) 6 | instance_type = var.instance_type 7 | tags = { 8 | 9 | Name = "xmr-miner-${count.index}" 10 | } 11 | security_groups = [ 12 | var.sec_group_name, 13 | ] 14 | vpc_security_group_ids = [ 15 | aws_security_group.miners.id, 16 | ] 17 | user_data = "${file("./xmrig/run-xmrig.sh")}" 18 | } 19 | 20 | resource "aws_security_group" "miners" { 21 | description = var.sec_group_description 22 | egress = [ 23 | { 24 | cidr_blocks = [ 25 | "0.0.0.0/0", 26 | ] 27 | description = "" 28 | from_port = 0 29 | ipv6_cidr_blocks = [] 30 | prefix_list_ids = [] 31 | protocol = "-1" 32 | security_groups = [] 33 | self = false 34 | to_port = 0 35 | }, 36 | ] 37 | ingress = [ 38 | for _port in var.port_list: 39 | { 40 | cidr_blocks = [ 41 | for _ip in var.ip_list: 42 | _ip 43 | ] 44 | description = "" 45 | from_port = _port 46 | ipv6_cidr_blocks = [] 47 | prefix_list_ids = [] 48 | protocol = "tcp" 49 | security_groups = [] 50 | self = false 51 | to_port = _port 52 | } 53 | ] 54 | name = var.sec_group_name 55 | } -------------------------------------------------------------------------------- /.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "4.39.0" 6 | hashes = [ 7 | "h1:tM2mSfH03Ert/Qd+EUMIavtwjPCM/no91VBH/8vobCE=", 8 | "zh:08e3d453bbeaccda3f4ab7ae45f81d515ab49a765ce2d43f060842bb2e653846", 9 | "zh:238a460231e9e6ca786b2cb2088a98edfc48f0e36c433edd7d65a250980f7566", 10 | "zh:4d5663c2cf521e91caddd5508b13759110bc21b2e9543ff6a9f8cf8d02af1aeb", 11 | "zh:5b397e46aac6db155b4b9162ac168010473d6309ae363301f0335184c1f50be6", 12 | "zh:7178536cfebc6423336798aead72fe774f4d8118ae19ffe6a6a1108fe60608d7", 13 | "zh:867c5269cea2fe15f7ea837507ad0fe97e8913be4348868b284c12217d689457", 14 | "zh:88db4bb188f68011cb05eefb3ea7e5741da1d9acdb3c7bd517e715dfc8c0cfc3", 15 | "zh:95b4da4bdbb2eb02333e52c2ced0c5f133d854f730e3744c0c239268c21feee6", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:9bbe67eaa03bfb293913431b39879385e42473bdb61be842fd78b3c89333f1ba", 18 | "zh:a06b9b5fbe8c84a0da431a22d9dd583143406846c1d8febe06f62fc89aeccd1d", 19 | "zh:cb925338b164e916f289e717f8ecaacf5fd5df56790ec6296158e76d6131b914", 20 | "zh:d9dbf68b0defc220085eda1348f439f724ce83a0636bec18dc83aa73fe2385d5", 21 | "zh:eb59e6234e73bd0d48fe372201155802c9b920711a1da078e5b07508271312ee", 22 | "zh:f68b2685ee86bcf314d74a20e97b5cbe0c63741827143f7a4ba7ec56555329dc", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS MONERO MINING 2 | 3 | `Terraform` script to start one or more *EC2* monero-mining (`XMRIG`) instances. ⛏️ 🪙 ☁️ 4 |
5 |
6 | 7 | ![](images/xmr.png) 8 | 9 |
10 |
11 | 12 | ## Disclaimer 13 | This repo is intended only as a terraform learning exercise applied to the aws cloud platform. 14 |
15 |
16 | - The author does not want to incentivize or promote monero mining. 17 | - The author does not promise any financial gain from mining monero on the contrary, at present time he does not recommend using it for economic purposes as the price charged by the provider for the use of the resources could be higher than the mining gain. 18 |
19 | 20 | **The author also assumes no responsibility for any weaponization of this repository in order to exploit other people's aws accounts for monero mining.** 21 | 22 | ## Prerequisites 23 | - monero wallet 24 | - aws account 25 | - Terraform installed on the dev machine 26 |
27 | 28 | Note: This script has been tested on `Ubuntu 22.04 LTS` 29 | 30 | ## Instructions 31 | clone this repo: 32 | ```console 33 | git clone https://github.com/R3DRUN3/aws-monero-mining.git \ 34 | && cd aws-monero-mining 35 | ``` 36 |
37 | 38 | Open the `./xmrig/run-xmrig.sh` file and modify it by inserting your monero wallet and the desired mining pool, 39 |
40 | alternatively you can create a new json configuration here. 41 |
42 | 43 | You can also modify the `vars.tf` file to change some variables according to your needs, 44 |
45 | for example yuo can change the ec2 instance type (the default is a very *resources-constrained* machine), the number of instances etc. 46 |
47 |
48 | Launch the Terraform provisioning: 49 | ```console 50 | terraform init && terraform apply -auto-approve 51 | ``` 52 |
53 | The whole procedure takes a few minutes 54 |
55 | In the end you can see the generated ec2 instances from your aws console: 56 |
57 |
58 | 59 | ![](images/ec2.png) 60 | 61 |
62 |
63 | 64 | or via `aws-cli` with the following command: 65 | ```console 66 | aws ec2 describe-instances 67 | ``` 68 | 69 | If you open one of the instances and inspect resources'usage with the `htop` command, 70 | you can see that `xmrig` is running and mining new monero! 71 |
72 |
73 | 74 | ![](images/cpu_usage.png) 75 | 76 |
77 |
78 | 79 | Based upon the mining pool that you put in your configuration, you should be able to 80 | see your current hashrate from the pool website: 81 |
82 |
83 | 84 | ![](images/pool.png) 85 | 86 |
87 |
88 | -------------------------------------------------------------------------------- /xmrig/run-xmrig.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | echo "Update repositories" 3 | sudo apt update 4 | echo "Building XMRIG" 5 | sudo apt install -y git build-essential cmake libuv1-dev libssl-dev libhwloc-dev && git clone https://github.com/xmrig/xmrig.git && mkdir xmrig/build && cd xmrig/build && cmake .. && make -j$(nproc) 6 | echo "writing xmrig config" 7 | cat > config.json << EOF 8 | { 9 | "api": { 10 | "id": null, 11 | "worker-id": null 12 | }, 13 | "http": { 14 | "enabled": false, 15 | "host": "127.0.0.1", 16 | "port": 0, 17 | "access-token": null, 18 | "restricted": true 19 | }, 20 | "autosave": true, 21 | "background": false, 22 | "colors": true, 23 | "title": true, 24 | "randomx": { 25 | "init": -1, 26 | "init-avx2": -1, 27 | "mode": "auto", 28 | "1gb-pages": true, 29 | "rdmsr": true, 30 | "wrmsr": true, 31 | "cache_qos": false, 32 | "numa": true, 33 | "scratchpad_prefetch_mode": 1 34 | }, 35 | "cpu": { 36 | "enabled": true, 37 | "huge-pages": true, 38 | "huge-pages-jit": false, 39 | "hw-aes": null, 40 | "priority": null, 41 | "memory-pool": false, 42 | "yield": true, 43 | "asm": true, 44 | "argon2-impl": null, 45 | "argon2": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 46 | "cn": [ 47 | [1, 0], 48 | [1, 2], 49 | [1, 4], 50 | [1, 6], 51 | [1, 8], 52 | [1, 9], 53 | [1, 10], 54 | [1, 11], 55 | [1, 12], 56 | [1, 13], 57 | [1, 14] 58 | ], 59 | "cn-heavy": [ 60 | [1, 0], 61 | [1, 2], 62 | [1, 4], 63 | [1, 6], 64 | [1, 8] 65 | ], 66 | "cn-lite": [ 67 | [1, 0], 68 | [1, 1], 69 | [1, 2], 70 | [1, 3], 71 | [1, 4], 72 | [1, 5], 73 | [1, 6], 74 | [1, 7], 75 | [1, 8], 76 | [1, 9], 77 | [1, 10], 78 | [1, 11], 79 | [1, 12], 80 | [1, 13], 81 | [1, 14], 82 | [1, 15] 83 | ], 84 | "cn-pico": [ 85 | [2, 0], 86 | [2, 1], 87 | [2, 2], 88 | [2, 3], 89 | [2, 4], 90 | [2, 5], 91 | [2, 6], 92 | [2, 7], 93 | [2, 8], 94 | [2, 9], 95 | [2, 10], 96 | [2, 11], 97 | [2, 12], 98 | [2, 13], 99 | [2, 14], 100 | [2, 15] 101 | ], 102 | "cn/upx2": [ 103 | [2, 0], 104 | [2, 1], 105 | [2, 2], 106 | [2, 3], 107 | [2, 4], 108 | [2, 5], 109 | [2, 6], 110 | [2, 7], 111 | [2, 8], 112 | [2, 9], 113 | [2, 10], 114 | [2, 11], 115 | [2, 12], 116 | [2, 13], 117 | [2, 14], 118 | [2, 15] 119 | ], 120 | "ghostrider": [ 121 | [8, 0], 122 | [8, 2], 123 | [8, 4], 124 | [8, 6] 125 | ], 126 | "rx": [0, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14], 127 | "rx/wow": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 128 | "cn-lite/0": false, 129 | "cn/0": false, 130 | "rx/arq": "rx/wow", 131 | "rx/keva": "rx/wow" 132 | }, 133 | "opencl": { 134 | "enabled": false, 135 | "cache": true, 136 | "loader": null, 137 | "platform": "AMD", 138 | "adl": true 139 | }, 140 | "cuda": { 141 | "enabled": false, 142 | "loader": null, 143 | "nvml": true 144 | }, 145 | "log-file": null, 146 | "donate-level": 1, 147 | "donate-over-proxy": 1, 148 | "pools": [ 149 | { 150 | "algo": null, 151 | "coin": null, 152 | "url": " eg: gulf.moneroocean.stream:10128", 153 | "user": "", 154 | "pass": "x", 155 | "rig-id": null, 156 | "nicehash": false, 157 | "keepalive": true, 158 | "enabled": true, 159 | "tls": false, 160 | "tls-fingerprint": null, 161 | "daemon": false, 162 | "socks5": null, 163 | "self-select": null, 164 | "submit-to-origin": false 165 | } 166 | ], 167 | "retries": 5, 168 | "retry-pause": 5, 169 | "print-time": 60, 170 | "health-print-time": 60, 171 | "dmi": true, 172 | "syslog": false, 173 | "tls": { 174 | "enabled": false, 175 | "protocols": null, 176 | "cert": null, 177 | "cert_key": null, 178 | "ciphers": null, 179 | "ciphersuites": null, 180 | "dhparam": null 181 | }, 182 | "dns": { 183 | "ipv6": false, 184 | "ttl": 30 185 | }, 186 | "user-agent": null, 187 | "verbose": 0, 188 | "watch": true, 189 | "pause-on-battery": false, 190 | "pause-on-active": false 191 | } 192 | EOF 193 | echo "Starting XMRIG" 194 | ./xmrig --------------------------------------------------------------------------------