ssh
Configuration location
Location | Description |
---|---|
/etc/ssh/ssh_config | System-wide configuration |
~/.ssh/config | User-specific configuration |
~/.ssh/id_{type} | Private key |
~/.ssh/id_{type}.pub | Public key |
~/.ssh/known_hosts | Login host |
~/.ssh/authorized_keys | Authorized 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
Command | Description |
---|---|
scp -r | Recursively copy entire directory |
scp -C | Compress data |
scp -v | Print detailed information |
scp -P 8080 | Use specific port |
scp -B | Batch mode (prevent passwords) |
scp -p | Preserve 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>