Skip to content

ssh

About 283 wordsLess than 1 minute

2019-04-13

Configuration location

LocationDescription
/etc/ssh/ssh_configSystem-wide configuration
~/.ssh/configUser-specific configuration
~/.ssh/id_{type}Private key
~/.ssh/id_{type}.pubPublic key
~/.ssh/known_hostsLogin host
~/.ssh/authorized_keysAuthorized login key

Execute remote command

ssh root@192.168.1.5 'ls -l'

# Call local script
ssh root@192.168.1.5 bash < script.sh

# Compress and download from server
ssh root@192.168.1.5 "tar cvzf - ~/source" > output.tgz

SCP

CommandDescription
scp -rRecursively copy entire directory
scp -CCompress data
scp -vPrint detailed information
scp -P 8080Use specific port
scp -BBatch mode (prevent passwords)
scp -pPreserve time and mode

Copy from remote to local

scp user@server:/dir/file.ext dest/

Copy between two servers

scp user@server:/file user@server:/dir

Copy from local to remote

scp dest/file.ext user@server:/dir

Copy the entire folder

scp -r user@server:/dir dest/

Copy all files in a folder

scp user@server:/dir/* dest/

Copy from server folder to current folder

scp user@server:/dir/* .

keygen

ssh-keygen -t rsa -b 4096 -C "your@mail.com"
  • -t specifies key type, rsa | ed25519 | dsa | ecdsa
  • -b specifies key length
  • -C specifies comment

Specify file name

ssh-keygen -f ~/.ssh/filename

Generate public key from private key

ssh-keygen -y -f private.key > public.pub

Change private key password

ssh-keygen -p -f ~/.ssh/id_rsa

Search from known_hosts

ssh-keygen -F <ip/hostname>

Search from known_hosts Delete from

ssh-keygen -R <ip/hostname>