diff --git a/README.md b/README.md index 011adf1..5efb4ea 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,28 @@ -# sshfsmanager -Utility for mounting / unmounting a remote filesystem via ssh. It will show you a simple dialogue window with your configured hosts in `~/.ssh/config` to connect to. -If already connected script will unmount the selected host mount. -* run command `wget -O ~/.local/bin/sshfsmanager https://raw.githubusercontent.com/bernermic/sshfsmanager/master/sshfsmanager` this simply downloads the script and places `sshfsmanager` into `~/.local/bin/` -* from CLI call `sshfsmanager` -* follow instructions from there +## 🛠 sshfsmanager install method -## Install -The script will check this preconditions and tell you if it missing something. -* assumes generated ssh-key `~/.ssh/id_rsa` is imported on remote host -* assumes ssh Host config `~/.ssh/config` is given +```bash +~$ sudo bash -c 'apt update -qq && apt -y install wget sshfs && wget -O - https://git.disroot.org/bullet/sshmanager/raw/branch/main/sshfsmanager | tee /usr/local/bin/sshfsmanager &> /dev/null && chmod +x /usr/local/bin/sshfsmanager' - -## Example config -### ssh key -For better security it is recommended to set up and use an ssh key `~/.ssh/id_rsa` for authentication. -[Read how to generate an SSH key](https://linuxize.com/post/how-to-setup-passwordless-ssh-login/). -### ssh config -Disclaimer: this is just a example `~/.ssh/config` replace *example* with your domain/user. +~$ sshfsmanager bullet # mount host is ~/.ssh/config ``` - Host example - Hostname example.com - User example - IdentityFile ~/.ssh/id_rsa - Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr - Compression yes +## 🛠 example ~/.ssh/config +```bash +Host * + KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512 + Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes256-ctr + MACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com + HostKeyAlgorithms ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-512,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com + +Host bullet + User secure + port 1337 + HostName 195.0.0.201 + VisualHostKey no + IdentityFile ~/.ssh/id_rsa + +~$ nano ~/.ssh/config + +~$ chmod 644 ~/.ssh/config ``` Further info [see SSH config](https://linuxize.com/post/using-the-ssh-config-file/). \ No newline at end of file diff --git a/sshfsmanager b/sshfsmanager index 1499315..e4b1aed 100755 --- a/sshfsmanager +++ b/sshfsmanager @@ -1,9 +1,11 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # Title: SSHFS Manager # Description: bash script for connect remote server via sshfs and standard ssh config # Author: Michael Berner +# Made: Secven Security # Project URL: https://github.com/bernermic/sshfsconnect +# Project URL: https://git.disroot.org/bullet/sshmanager # Version 1.0.0 # Licence: GNU General Public License v3.0 @@ -12,28 +14,19 @@ SSHFS_OPTIONS="auto_cache,kernel_cache,reconnect,transform_symlinks,follow_symli # check preconditions check() { - command -v sshfs >/dev/null 2>&1 || { echo >&2 "I require sshfs but it's not installed. Please install sshfs via package manager."; exit 1;} - command -v zenity >/dev/null 2>&1 || { echo >&2 "I require zenity but it's not installed. Please install zenity via package manager."; exit 1;} test $(grep "^user_allow_other" /etc/fuse.conf) || { echo >&2 "I require user_allow_other in /etc/fuse.conf. Aborting."; exit 1;} - test $(grep "^Host " ~/.ssh/config | wc -l) -gt 0 || { echo >&2 "I require a configured Host in ~/.ssh/config. Please see https://github.com/bernermic/sshfsconnect/blob/master/README.md#ssh-config."; exit 1;} -} - -# select a host -select() { - host="$(zenity --list --radiolist --column Select --column Host $(echo $(grep "^Host " ~/.ssh/config | awk '{print "FALSE "$2}')))" - - echo $host + test $(grep "^Host " ~/.ssh/config | wc -l) -gt 0 || { echo >&2 "I require a configured Host in ~/.ssh/config. Please see https://git.disroot.org/bullet/sshmanager."; exit 1;} } # adding default config configure() { - sshfsconfig="$CONFIG_DIR/$1" + local sshfsconfig="$CONFIG_DIR/$1" - test -f $sshfsconfig && return + test -f "$sshfsconfig" && return - test -d $config || mkdir -p $config - echo "DIR=/" > $sshfsconfig - echo "OPTIONS=$SSHFS_OPTIONS" >> $sshfsconfig + test -d "$config" || mkdir -p "$config" &> /dev/null + echo "DIR=/" > "$sshfsconfig" + echo "OPTIONS=$SSHFS_OPTIONS" >> "$sshfsconfig" echo "You can modify the default config here: $sshfsconfig" } @@ -42,13 +35,16 @@ toggleMount() { host=$1 mount=~/mount/$host - test -z "$(mount | grep $mount)" && mnt $host $mount || unmount $mount + if test -z "$(mount | grep "$mount")" + then + mnt "$host" "$mount" || unmount "$mount" + fi } unmount() { mount=$1 - fusermount -u $mount + fusermount -u "$mount" test $? = 0 && echo "$mount is unmounted" || echo "Error occured while unmount" } @@ -58,25 +54,20 @@ mnt() { mount=$2 sshfsconfig="$CONFIG_DIR/$1" - dir="$(grep "^DIR=" $sshfsconfig | awk -F '=' '{print $2}')" - options="$(grep "^OPTIONS=" $sshfsconfig | awk -F '=' '{print $2}')" + dir="$(grep "^DIR=" "$sshfsconfig" | awk -F '=' '{print $2}')" + options="$(grep "^OPTIONS=" "$sshfsconfig" | awk -F '=' '{print $2}')" test -d "$mount" || mkdir -p "$mount" - sshfs $host:$dir $mount -o $options + sshfs "$host":"$dir" "$mount" -o "$options" test $? = 0 && echo "$mount is mounted" || echo "Error occured while mount" } - -# check if all requirements are met -check - -# choose host -host="$(select)" -test -z $host && { echo >&2 "No host selected. Aborting."; exit 1; } - -# configure the chosen host -configure $host - -# mount or unmount filesystem -toggleMount $host \ No newline at end of file +init() { + # check if all requirements are met + check + # configure the chosen host + configure "$1" + # mount or unmount filesystem + toggleMount "$1" +}