List SSH connections

I was “lazy” to reconnect and get the custom remote SSH port so got if from

Advertisements

Passwordless ssh not working

I was getting the following with ssh -v user@remote_host

debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/mike/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method
debug1: Next authentication method: password

The solution idea came from http://askubuntu.com/a/90465/168459 to fix .ssh dir permissions and .ssh/authorized_keys

Later during investigation after login with password and debug turned on SSH complained with:

debug1: Remote: Ignored authorized keys: bad ownership or modes for file /home/REMOTE_HOST_USER/.ssh/authorized_keys

Open new Chrome window from command line via SSH

I switch between computers and sometimes when I’m switching I need to push an URL/prepare a window so found a solution with the following command:

mike@remotehost $ export DISPLAY=:0; nohup chromium --new-window https://github.com/deployphp/deployer#installation

UPDATE 2017-06-18

SSHFS mounting without password with SSH keys

First we need to generate public and private keys on our host.
When prompted for passphrase just hit enter to go without it

nevillegroup@shell:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/nevillegroup/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/nevillegroup/.ssh/id_rsa.
Your public key has been saved in /home/nevillegroup/.ssh/id_rsa.pub.

We need to add our public key into authorized_keys file and upload it to the remote host into the .ssh directory.

nevillegroup@shell:~$ cat .ssh/id_rsa.pub > authorized_keys

Now we can create a bash script for mounting the remote directory

!/bin/bash

USERID="YOUR_UID"
USER="example"
HOST="example.com"
MOUNT_DIR="/home/example/examplecom_sshfs"

# create dir if it doesn't exists
if [ ! -d "$MOUNT_DIR" ]; then
umount $MOUNT_DIR &> /dev/null
mkdir $MOUNT_DIR
fi

# to check your uid use command `id`
sshfs -C -o uid=$USERID,ssh_command='ssh -i ~/.ssh/id_rsa',workaround=rename $USER@$HOST:. $MOUNT_DIR

Add executable flag to the file and you ready to mount with the script

nevillegroup@shell:~$ chmod +x bin/sshfs_examplecom
nevillegroup@shell:~$ ./bin/sshfs_examplecom
nevillegroup@shell:~$ ls /home/example/examplecom_sshfs
dev/ git/ logs/ sub/ web/

Backup with RSYNC and SSH authorized key

Finally I wrote my rsync backup script v. 0.1
https://raw.github.com/mikaelz/bin/master/backup.sh


#!/bin/sh

# ~/bin/backup.sh
#
# Some help from
# http://www.sakana.fr/blog/2008/05/07/securing-automated-rsync-over-ssh/
# https://wiki.archlinux.org/index.php/Rsync#Automated_backup_with_SSH
# https://wiki.archlinux.org/index.php/Full_System_Backup_with_rsync
# https://www.linux.com/news/enterprise/storage/8200-back-up-like-an-expert-with-rsync
# Thanks

# man rsync
# -v be verbose
# -h human readable bytes
# -a, --archive archive mode; same as -rlptgoD (no -H) -H hard-links
# -z compress data during transfer
# --progress show file transfer progress
# -e remote shell to use

time rsync -vhaz --progress -e "ssh -i .ssh/id_rsa" \
--exclude ".DS_Store" \
--exclude "._.DS_Store" \
--exclude "Thumbs.db" \
--exclude "thumbs.db" \
--exclude "desktop.ini" \
--exclude ".svn" \
--exclude ".git" \
/Volumes/data/Dropbox/ \
nevillegroup@shell.websupport.sk:/home/nevillegroup/optimalizaciaseosk/backup/Dropbox/
# >> backup.log # log output
# &> /dev/null


# needs FTP password
# time rsync -vhaz --progress -e ssh \
# --exclude ".DS_Store" \
# --exclude "._.DS_Store" \
# --exclude "Thumbs.db" \
# --exclude "thumbs.db" \
# --exclude "desktop.ini" \
# --exclude ".svn" \
# --exclude ".git" \
# /Volumes/data/Dropbox/ \
# optimalizaciaseo.sk@optimalizaciaseo.sk:/backup/Dropbox/
# # >> backup.log # log output
# # &> /dev/null