SSH

All the SSH things.

Permissions

Make sure the files and folders have correct permissions set up:

  • 0700 for ~/.ssh
  • 0644 for ~/.ssh/config
  • 0600 for ~/.ssh/id_rsa
  • 0644 for ~/.ssh/id_rsa.pub

Passwordless SSH

Only create a new SSH key if you don't have an existing one. In that case, do:

ssh-keygen -t rsa -b 4096 -C "your_email@domain.com".

Now copy existing SSH key to server:

ssh-copy-id remote_username@server_ip_address

You'll need to enter the remote user's password.

Now you should be able to login with ssh remote_username@server_ip_address but with no password.

To log in without needing the username as well, either add appropriate entry with remote host's username into the client device ~/ssh/config as below, or log into the server and create a user matching the client device's user and repeat the ssh-copy-id to that user. If you go this route, be sure to add your new user to sudo:

sudo adduser newusername
sudo usermod -aG sudo newusername

Be sure to then update the remote host's /etc/ssh/sshd_config to disable password authentication:

PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM yes
PermitRootLogin no

And sudo systemctl restart ssh. You can now log in with SSH passwordless (pubkey) authentication.

xclip

To be able to xclip over SSH, make sure it's installed on the client and remote host.

On the client, edit ~/.ssh/config and add ForwardX11 yes as needed, for example:

Host ovh3
    HostName 51.38.128.6
    User marc
    ForwardX11 yes

On the remote host, edit /etc/ssh/sshd_config and add X11Forwarding yes. AddressFamily inet may also be needed.

Then you can do:

cat file.yml | xclip -i and then echo newfile.yml | xclip -o

Or copy to the WM clipboard with:

cat file.yml | xclip -selection clipboard, then paste with CTRL-SHIFT-V or right-click paste.

View SSH Sessions

To see all current SSH sessions:

sudo netstat -tnpa | grep 'ESTABLISHED.*sshd'

or ss | grep ssh

or last -p now

Xauthority

If you get /usr/bin/xauth: file /home/md/.Xauthority does not exist on first login, make sure these are uncommented out in /etc/ssh/sshd_config:

X11Forwarding yes
X11DisplayOffset 10 
X11UseLocalhost yes