feat: make types and languages selectable
This commit is contained in:
@@ -3,6 +3,7 @@ title: Mounting a SFTP storage in GNU/Linux
|
||||
date: 2014-01-13T14:42:01+00:00
|
||||
aliases: /blog/2014/mounting-a-sftp-storage-in-gnu-linux
|
||||
categories:
|
||||
- blog
|
||||
- english
|
||||
tags:
|
||||
- bash
|
||||
@@ -47,10 +48,10 @@ The only prerequisite: You need a server/webspace/storage with full SSH access.
|
||||
Now we come to the technical part. For this post, following data is used. Most likely, this will look different in your case.
|
||||
|
||||
```
|
||||
SSH-Server: server1.net
|
||||
Username on server: client
|
||||
Home directory of user on server: /home/client
|
||||
Username local machine: user
|
||||
SSH-Server: server1.net
|
||||
Username on server: client
|
||||
Home directory of user on server: /home/client
|
||||
Username local machine: user
|
||||
Local mount directory: /home/user/remote/server1
|
||||
```
|
||||
|
||||
@@ -87,9 +88,9 @@ In the next step, we will make the connection and mounting more comfortable, eve
|
||||
Now that you know how (and that) the system works, we will make it easier. Of course it is quite annoying to type in the whole server-address and port each time. Instead of _sshfs -p 22 client@server1.net[…]_, you can simply type _sshfs server1_. How? Just open the SSH configuration file _/home/user/.ssh/config_ with you desired text editor and add:
|
||||
|
||||
```
|
||||
Host server1
|
||||
HostName server1.net
|
||||
Port 22
|
||||
Host server1
|
||||
HostName server1.net
|
||||
Port 22
|
||||
User client
|
||||
```
|
||||
|
||||
@@ -109,7 +110,7 @@ Let’s say, the public key is a chest that no one except the owner can open. In
|
||||
It is quite easy to make this system happen. Again we need a terminal to generate the two keys:
|
||||
|
||||
```bash
|
||||
cd ~/.ssh/
|
||||
cd ~/.ssh/
|
||||
ssh-keygen -t dsa
|
||||
```
|
||||
|
||||
@@ -141,86 +142,86 @@ And these steps were quite important for the next section where we will write a
|
||||
Our setting is very smooth now, but it could still be improved. If you want to connect to many servers and don’t want to use your shell every time or don’t want to remember the HOSTs you used in your .ssh/config, you’re free to modify and use this shell script:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
### VARIABLES TO BE CHANGED ###
|
||||
# Preconfigured HOSTs in ~/.ssh/config that should be used
|
||||
PRESSH[0]=server1
|
||||
PRESSH[1]=server2
|
||||
PRESSH[2]=server3
|
||||
|
||||
# Local directory where the remote storages should be mounted to
|
||||
LOCALMOUNTDIR=/home/user/remote
|
||||
|
||||
### THE SCRIPT BEGINS HERE ###
|
||||
|
||||
# Add SSH key to local keyring if not already happened
|
||||
function sshadd {
|
||||
ssh-add -l > /dev/null || ssh-add
|
||||
}
|
||||
|
||||
# Choose preconfigured HOST to mount
|
||||
function mount {
|
||||
if ! SSH=$(zenity --list \
|
||||
--height=300 \
|
||||
--text="Please choose. Cancel to unmount drives." \
|
||||
--title="Choose SSH server" \
|
||||
--column "Preconfigured SSH servers" \
|
||||
${PRESSH[*]}); then
|
||||
unmountquestion # If you press cancel, it should ask you to unmount all drives
|
||||
fi
|
||||
|
||||
# If you double click on an entry, it gives 'server1|server1' as result instead of 'server1'
|
||||
# This command cuts of everything after |
|
||||
SSH=$(echo $SSH | awk -F\| '{ print $1 }')
|
||||
|
||||
# Make a local directory if not available
|
||||
if [ ! -e "$LOCALMOUNTDIR"/"$SSH" ]; then
|
||||
mkdir -p "$LOCALMOUNTDIR"/"$SSH"
|
||||
fi
|
||||
|
||||
# Command to mount actually
|
||||
sshfs "$SSH": "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks &
|
||||
|
||||
quitquestion # one more ssh server or quit?
|
||||
|
||||
}
|
||||
|
||||
# Ask if all preconfigured SSHFS drives should be unmounted
|
||||
function unmountquestion {
|
||||
zenity --question --text="Unmount all preconfigured\nSSHFS drives now?"
|
||||
if [ "$?" = "0" ]; then
|
||||
unmount # unmount function
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Procedure to unmount all preconfigured SSHFS drives and exit program afterwards
|
||||
function unmount {
|
||||
for ((i = 0; i < ${#PRESSH[*]}; i++))
|
||||
do
|
||||
fusermount -u "$LOCALMOUNTDIR"/"${PRESSH[$i]}"
|
||||
echo ""${PRESSH[$i]}" unmounted."
|
||||
done
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Should another SSHFS storage be mounted?
|
||||
function quitquestion {
|
||||
zenity --question \
|
||||
--text="Mount another SSHFS storage?"
|
||||
if [ "$?" = "1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
sshadd # sshadd function
|
||||
|
||||
# Loop for endless mounts until stopped by unmount or unmountquestion
|
||||
while :
|
||||
do
|
||||
mount # mount function
|
||||
#!/bin/bash
|
||||
|
||||
### VARIABLES TO BE CHANGED ###
|
||||
# Preconfigured HOSTs in ~/.ssh/config that should be used
|
||||
PRESSH[0]=server1
|
||||
PRESSH[1]=server2
|
||||
PRESSH[2]=server3
|
||||
|
||||
# Local directory where the remote storages should be mounted to
|
||||
LOCALMOUNTDIR=/home/user/remote
|
||||
|
||||
### THE SCRIPT BEGINS HERE ###
|
||||
|
||||
# Add SSH key to local keyring if not already happened
|
||||
function sshadd {
|
||||
ssh-add -l > /dev/null || ssh-add
|
||||
}
|
||||
|
||||
# Choose preconfigured HOST to mount
|
||||
function mount {
|
||||
if ! SSH=$(zenity --list \
|
||||
--height=300 \
|
||||
--text="Please choose. Cancel to unmount drives." \
|
||||
--title="Choose SSH server" \
|
||||
--column "Preconfigured SSH servers" \
|
||||
${PRESSH[*]}); then
|
||||
unmountquestion # If you press cancel, it should ask you to unmount all drives
|
||||
fi
|
||||
|
||||
# If you double click on an entry, it gives 'server1|server1' as result instead of 'server1'
|
||||
# This command cuts of everything after |
|
||||
SSH=$(echo $SSH | awk -F\| '{ print $1 }')
|
||||
|
||||
# Make a local directory if not available
|
||||
if [ ! -e "$LOCALMOUNTDIR"/"$SSH" ]; then
|
||||
mkdir -p "$LOCALMOUNTDIR"/"$SSH"
|
||||
fi
|
||||
|
||||
# Command to mount actually
|
||||
sshfs "$SSH": "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks &
|
||||
|
||||
quitquestion # one more ssh server or quit?
|
||||
|
||||
}
|
||||
|
||||
# Ask if all preconfigured SSHFS drives should be unmounted
|
||||
function unmountquestion {
|
||||
zenity --question --text="Unmount all preconfigured\nSSHFS drives now?"
|
||||
if [ "$?" = "0" ]; then
|
||||
unmount # unmount function
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Procedure to unmount all preconfigured SSHFS drives and exit program afterwards
|
||||
function unmount {
|
||||
for ((i = 0; i < ${#PRESSH[*]}; i++))
|
||||
do
|
||||
fusermount -u "$LOCALMOUNTDIR"/"${PRESSH[$i]}"
|
||||
echo ""${PRESSH[$i]}" unmounted."
|
||||
done
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Should another SSHFS storage be mounted?
|
||||
function quitquestion {
|
||||
zenity --question \
|
||||
--text="Mount another SSHFS storage?"
|
||||
if [ "$?" = "1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
sshadd # sshadd function
|
||||
|
||||
# Loop for endless mounts until stopped by unmount or unmountquestion
|
||||
while :
|
||||
do
|
||||
mount # mount function
|
||||
done
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user