## Getting Started
## Connecting
Connect to a server (default port 22)
$ ssh root@192.168.1.5
Connect on a specific port
$ ssh root@192.168.1.5 -p 6222
Connect via pem file (0400 permissions)
$ ssh -i /path/file.pem root@192.168.1.5
See: SSH Permissions
## Executing
Executes remote command
$ ssh root@192.168.1.5 'ls -l'
Invoke a local script
$ ssh root@192.168.1.5 bash < script.sh
Compresses and downloads from a server
$ ssh root@192.168.1.5 "tar cvzf - ~/source" > output.tgz
## SCP
Copies from remote to local
$ scp user@server:/dir/file.ext dest/
Copies between two servers
$ scp user@server:/file user@server:/dir
Copies from local to remote
$ scp dest/file.ext user@server:/dir
Copies a whole folder
$ scp -r user@server:/dir dest/
Copies all files from a folder
$ scp user@server:/dir/* dest/
Copies from a server folder to the current folder
$ scp user@server:/dir/* .
## Config location
File Path | Description |
---|---|
/etc/ssh/ssh_config |
System-wide config |
~/.ssh/config |
User-specific config |
~/.ssh/id_{type} |
Private key |
~/.ssh/id_{type}.pub |
Public key |
~/.ssh/known_hosts |
Known Servers |
~/.ssh/authorized_keys |
Authorized login key |
## SCP Options
Options | Description |
---|---|
scp -r |
|
scp -C |
|
scp -v |
Prints |
scp -P 8080 |
Uses a specific |
scp -B |
|
scp -p |
## Config sample
Host server1
HostName 192.168.1.5
User root
Port 22
IdentityFile ~/.ssh/server1.key
Launch by alias
$ ssh server1
See: Full Config Options
## SSH keygen
## ssh-keygen
$ ssh-keygen -t rsa -b 4096 -C "your@mail.com"
- | - | - |
---|---|---|
-t |
Type of key | |
-b |
The number of bits in the key | |
-C |
Provides a new comment |
Generate an RSA 4096 bit key with email as a comment
## Generate
Generate a key interactively
$ ssh-keygen
Specify filename
$ ssh-keygen -f ~/.ssh/filename
Generate public key from private key
$ ssh-keygen -y -f private.key > public.pub
Change comment
$ ssh-keygen -c -f ~/.ssh/id_rsa
Change private key passphrase
$ ssh-keygen -p -f ~/.ssh/id_rsa