179 shaares
2 results
tagged
ssh
INSTALL
MANJARO
yay -S autofs sshfs
CONFIGURATION
SSHFS
SSH KEY
Do not forget to put root key in remote server !!
autofs use root rights to connect
MANJARO
/etc/autofs/auto.master.d/cluster.autofs
echo "/home/cluster /etc/autofs/auto.sshfs uid=1000,gid=1000, --timeout=30, --ghost" | sudo tee /etc/autofs/auto.master.d/cluster.autofs
/etc/autofs/auto.sshfs
echo "node1 -fstype=fuse,port=2002,rw,allow_other :sshfs\#root@node1\:/" | sudo tee /etc/autofs/auto.sshfs
TEST SSHFS
path=/tmp/node1
mkdir -p ${path}
sshfs root@node1:/ ${path}
TUNNEL
backgroung tunnel
ssh -fNC [USER_HOST]@[IP_HOST] -p [PORT_HOST] -L [PORT_LISTENING]:[HOST_REMOTE_MYSQL]:[PORT_REMOTE_MYSQL]
backgroung tunnel with socket
# create tunnel
ssh -MS $SOCKET -fnNT -L 50000:localhost:3306 $USER@$HOST
# check connection
ssh -S $SOCKET -O check $USER@$HOST
# exit connection
ssh -S $SOCKET -O exit $USER@$HOST
# ctrl_cmd : check forward cancel stop exit
ssh autoclosing after command
ssh -f -o ExitOnForwardFailure=yes -L 3306:localhost:3306 sleep 10
mysql -e 'SHOW DATABASES;' -h 127.0.0.1
ssh -> ssh -> ssh
spawn ssh usr1@IP1 ssh usr2@IP2 $CMD # CMD is the command you wanna execute on B2
expect "password"
send "PWD_USER1\n"
expect "password"
send "PWD_USER2\n"
expect eof
exit
TUNNEL ControlMaster
ssh master control (not so efficient...)
~/.ssh/config
ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r
sshfs
user="root"
ip="91.121.112.140"
path_base="/mnt/sshfs"
path_remote="vz/share"
path_local=$path_base/$path_remote
[ ! -d "$path_local" ] && sudo mkdir -p "$path_local"
sudo chown 1000:1000 -R "$path_local"
sshfs -o reconnect -o big_writes ${user}@${ip}:/"$path_remote" "$path_local"
ll "$path_local"
umount "$path_local" && sudo rm -fR "${path_base}/${pathremote%%/*}"
examples
# rspamd
ssh -fN root@91.121.112.140 -L 8080:10.0.0.180:11334
TUNNELING mysql with ssl & keep alive tunnel without command
ssh -fNC [user_host]@[ip_host] -p [port_host] -L [port_listening]:[host_remote_mysql]:[port_remote_mysql]
# connect mysql
mysql -h 127.0.0.1 -u [USER_REMOTE_MYSQL] -p '[PASSWORD_REMOTE_MYSQL]' -P [PORT_LISTENING]
# look ssh connections
lsof -i -n | grep ssh
# kill ssh process
kill [PID_PROCESS]
kill $(lsof -i -n |grep ssh |grep LISTEN| xargs| awk '{print $2}')
examples
ssh -fNC root@91.121.112.140 -L 3306:10.0.0.120:3306
mysql -h 127.0.0.1 -u roothost -p '[$mysql_pwd]' -P 3306
ssh -fNC root@91.121.112.140 -p 20120 -L 3333:localhost:3306
mysql -h 127.0.0.1 -u root -p '[$mysql_pwd]' -P 3333
TUNNELING mysql with ssl with a mysql client command
ssh -f [user_host]@[ip_host] -p [port_host] -L [port_listening]:[host_remote_mysql]:[port_remote_mysql] sleep 5; \
mysql -h 127.0.0.1 -u [user_remote_mysql] -p '[password_remote_mysql]' -P [port_listening]
UTILITIES
# list of ssh connection
netstat -n --protocol inet | grep ':22'
# launch remote command with local file
ssh $USER@$HOST $COMMAND < $FILE