Skip to content

Instantly share code, notes, and snippets.

@miranda-zhang
Last active August 5, 2023 20:53
Show Gist options
  • Save miranda-zhang/74a2e1c5888b69f170792a107cd67011 to your computer and use it in GitHub Desktop.
Save miranda-zhang/74a2e1c5888b69f170792a107cd67011 to your computer and use it in GitHub Desktop.
ssh related commands

SSH on Windows

Easiest way to setup is probably installing Git Bash: More instructions can be found here.

Win host file dir

c:\Windows\System32\Drivers\etc\hosts

https://superuser.com/q/487402/273113

SSH in Ubuntu 16.04 LTS

apt install openssh-server
service ssh status

Check/change settings:

cat /etc/ssh/sshd_config
service ssh restart

More details see here

Generate a new SSH key

ssh-keygen -t rsa -C "miranda.zhang.q@gmail.com"

ssh-copy-id

Add your key to host for user to enable a keyed or passwordless login

ssh-copy-id user@host

ssh-copy-id is (about) equivalent to the following steps:

Local:

scp ~/.ssh/id_rsa.pub root@10.0.2.205:
ssh root@10.0.2.205

Remote:

cat id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
rm -f id_rsa.pub

To connect

  • ssh user@host – connect to host as user
  • ssh -p port user@host – connect to host on port port as user

Remember passphrase

Start ssh-agent

$ eval `ssh-agent -s`
$ ssh-add
$ ssh-add -l
$ ssh-add -D

I tried this method: add private key permanently ,but seems I still need to run ssh add, to add the passphrase, everytime I open a new terminal, I'm not sure if this is by design for security reason. Someone suggeted gnome-keyring may provide funtionalities to remember passphrase between reboots.

REMOTE HOST IDENTIFICATION HAS CHANGED

ssh-keygen -R 192.168.3.10

https://stackoverflow.com/a/23150466/646732

Pseudo-terminal

ssh -tt root@$remote_server_ip << EOF
  
    echo "Running installation script..."
    source install_scripts_only/install.sh

EOF

https://stackoverflow.com/a/26436163/646732

Add host name for remote

So you don't have to remember host ip.

echo "10.0.2.203 miranda-vm # testing VM" >> /etc/hosts

https://support.rackspace.com/how-to/modify-your-hosts-file/

for example, you can also add comments:

10.0.2.203 miranda-vm # testing VM
10.0.2.96 midpoint-dev # MidPoint server
10.0.2.98 jellyfish-dev # Jellyfish dev server

ssh -v root@miranda-vm

Set hostname for self

To something easily recognizable:

hostnamectl set-hostname 'miranda-vm'

Need to exit then login to see change taking effect.

https://askubuntu.com/questions/9540/how-do-i-change-the-computer-name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment