├── Dockerfile.template ├── LICENSE ├── README.md ├── img └── env.png ├── main.py ├── requirements.txt └── start.sh /Dockerfile.template: -------------------------------------------------------------------------------- 1 | FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3-stretch-run 2 | 3 | # Install Dropbear. 4 | RUN install_packages dropbear 5 | 6 | # Install Flask 7 | COPY ./requirements.txt /requirements.txt 8 | RUN pip install -r /requirements.txt 9 | 10 | COPY . /usr/src/app 11 | WORKDIR /usr/src/app 12 | 13 | CMD ["bash", "start.sh"] 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Praneeth 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | balena-ssh 2 | ========= 3 | This is a basic balena project that runs dropbear on boot which allows for ssh access. It's currently running a python script, but you could run any language you like as long as there is a continous process running to keep the container open to outside connections, in this case we are running a flask server. 4 | 5 | If your running a node.js project with balena and would like ssh access you should look [here](https://github.com/balena-io-playground/ssh-node). 6 | 7 | NOTE: This container enables SSH access as root with a PASSWORD stored in plain text - Do not use in production without modifications. 8 | 9 | #### SSH into your device. 10 | 11 | Add an environment variable called PASSWD with the value to set as root password. 12 | 13 | ![alt text](https://github.com/balena-io-playground/balena-ssh-python/blob/master/img/env.png?raw=true "creating envar") 14 | 15 | Then run 16 | 17 | ```sh 18 | $ ssh root@ 19 | ``` 20 | 21 | The code you just pushed is kept in the app directory. 22 | 23 | ```sh 24 | $ cd /usr/src/app 25 | ``` 26 | 27 | 28 | At after pushing you may encounter and re-sshing back into the device you may encounter this error message as the host key changes when an update occurs on the device. 29 | 30 | 31 | ```sh 32 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 33 | @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ 34 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 35 | IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! 36 | Someone could be eavesdropping on you right now (man-in-the-middle attack)! 37 | It is also possible that a host key has just been changed. 38 | ``` 39 | 40 | To get around this remove the key. 41 | 42 | ```sh 43 | $ ssh-keygen -R 44 | ``` 45 | 46 | It will then work as expected 47 | 48 | ```sh 49 | $ ssh root@ 50 | ``` 51 | 52 | -------------------------------------------------------------------------------- /img/env.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balena-io-experimental/balena-ssh-python/2185b8518ea3cf315e47fd2ce2e93cdea9eee29d/img/env.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | @app.route('/') 5 | def hello_world(): 6 | return 'Hello World Balena!' 7 | 8 | if __name__ == '__main__': 9 | app.run(host='0.0.0.0',port=80) 10 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==0.10.1 -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Set the root password as root if not set as an ENV variable 4 | export PASSWD=${PASSWD:=root} 5 | 6 | # Set the root password 7 | echo "root:$PASSWD" | chpasswd 8 | 9 | #Spawn dropbear 10 | dropbear -E -F & 11 | 12 | # Starts application from here 13 | python3 main.py 14 | --------------------------------------------------------------------------------