piCMD: Simplified remote pi management
Posted: Thu May 01, 2014 1:15 pm
Since not everyone is familiar with the Linux commandline, SSH, SCP, rsync, UFW, etc.. I made some scripts that might make things a bit easier. At least it will take away the need to remember lot's of commands and their syntax when doing basic management tasks from a remote computer.
Since I think it's useful for anyone that owns a Pi to know the basics of executing commands in a terminal this script has no GUI. This way it can be used on any PC that includes the bash shell and an ssh client program, it should even work from Windows if you edit the filesystem path's and names of the bash and ssh executables in the script.
Features:
[Picmd Version 0.0.1]
Usage:
picmd [action] [arguments]
Actions: Arguments:
configure : Create new config file
add-key : Upload public ssh key to Pi
connect : Open a remote BASH shell
execute - Any command
execute-x11 - gui-program (forward remote X11 apps to local xorg)
reboot
poweroff
list-shares : List remote shares
sshmount - /remote/directory /local/mount/point
root-sshmount - /remote/directory /local/mount/point
unmount - /local/mount/point
service - service-name [start|stop|restart|status]
- list (lists all available services)
autostart - service-name [enable|disable]
firewall - port/type [allow|deny]
- [enable|disable|status]
upload - local/file /remote/directory
download - /remote/file /local/directory
update : Update server apt sources
upgrade : Perform update and do dist-upgrade
install - app-1 app-2 app-ect
uninstall - app-1 app-2 app-ect
apt-search - app-name
clean : clean apt cache + autoremove orphaned packages
mplay - /remote/path/to/music/dir/or/file.mp3
mplaylist - /remote/path/to/playlist.txt
help : Display this help text
Examples:
Start a Bash shell on the Pi:
Execute "ls /var/www/html/" on the Pi:
Mount and unmount your Pis music folder on your workstation:
Install/Remove/Update/Search Software:
Upload/Download files to/from the Pi:
Real world examples:
Install the NginX webserver, enable it to start at system boot and allow firewall traffic on TCP port 80:
List available devices on the Pi, mount a device via sshfs and dismount it when done:
So, that's how things work.... Now if you like to try it:
Install:
Use GIT to clone the scripts to your PC or download a zip archive.:
Change to the picmd directory (extract the zip first if you didn't use GIT):
Execute the script in the downloaded directory:
The first time you execute it you'll be asked for your username (defaults to root), the Pi's IP address and ssh port (22) to configure the scripts. If you need to run this wizard again just execute: picmd configure
To be able to run the script from any directory you need to copy it in your executable PATH:
Set-up public key authentication for ssh (if you already have an ssh keyring skip the ssh-keygen step):
If you like to use the mplaylist scripts you need to copy these to an executable dir on your Pi. You can use picmd to do this:
Since I think it's useful for anyone that owns a Pi to know the basics of executing commands in a terminal this script has no GUI. This way it can be used on any PC that includes the bash shell and an ssh client program, it should even work from Windows if you edit the filesystem path's and names of the bash and ssh executables in the script.
Features:
[Picmd Version 0.0.1]
Usage:
picmd [action] [arguments]
Actions: Arguments:
configure : Create new config file
add-key : Upload public ssh key to Pi
connect : Open a remote BASH shell
execute - Any command
execute-x11 - gui-program (forward remote X11 apps to local xorg)
reboot
poweroff
list-shares : List remote shares
sshmount - /remote/directory /local/mount/point
root-sshmount - /remote/directory /local/mount/point
unmount - /local/mount/point
service - service-name [start|stop|restart|status]
- list (lists all available services)
autostart - service-name [enable|disable]
firewall - port/type [allow|deny]
- [enable|disable|status]
upload - local/file /remote/directory
download - /remote/file /local/directory
update : Update server apt sources
upgrade : Perform update and do dist-upgrade
install - app-1 app-2 app-ect
uninstall - app-1 app-2 app-ect
apt-search - app-name
clean : clean apt cache + autoremove orphaned packages
mplay - /remote/path/to/music/dir/or/file.mp3
mplaylist - /remote/path/to/playlist.txt
help : Display this help text
Examples:
Start a Bash shell on the Pi:
Code: Select all
picmd connectCode: Select all
picmd execute ls /var/www/html/Code: Select all
picmd sshmount /media/music /home/username/Music/
picmd unmount /home/username/Music/Code: Select all
picmd install package-name otherPackage stuff
picmd uninstall package-name
picmd upgrade
picmd apt-search firefoxCode: Select all
picmd upload /home/username/nice-image.png /var/www/html/my-site/
picmd download /var/www/html/my-site/index.html /home/username/Workspace/my-site/Install the NginX webserver, enable it to start at system boot and allow firewall traffic on TCP port 80:
Code: Select all
picmd upgrade
picmd install apache2
picmd autostart apache2 enable
picmd firewall 80/tcp allow
picmd firewall 22/tcp allow
picmd firewall enableCode: Select all
mkdir pi-mount
picmd list-shares
picmd sshmount /media/myusbdisk pi-mount/
# Open the pi-mount folder in your file manager
picmd unmount pi-mount/Install:
Use GIT to clone the scripts to your PC or download a zip archive.:
Code: Select all
git clone https://github.com/socialdefect/picmd.gitCode: Select all
cd picmdCode: Select all
./picmdTo be able to run the script from any directory you need to copy it in your executable PATH:
Code: Select all
sudo cp picmd /usr/local/bin/Code: Select all
ssh-keygen
# Press [Enter] twice to create a key pair with empty password
picmd add-keyCode: Select all
picmd upload *mplaylist /usr/local/bin/
picmd install mplayer