Skip to content

Latest commit

 

History

History
executable file
·
65 lines (45 loc) · 1.29 KB

ssh.md

File metadata and controls

executable file
·
65 lines (45 loc) · 1.29 KB

Install

sudo apt-get install openssh-server

Connect

ssh -p PORT USER@SERVER_IP

# Execute one command and exit.
ssh -p PORT USER@SERVER_IP ls

SSH in Virtual Machine needs a port forwarding rule in network settings for the VM. Name ssh, host port 3022, guest port 22.

# SSH to local VM via port forwarding.
ssh -p 3022 [email protected]

sudo command

# It will ask for the root password in the remote machine
ssh -t [email protected] "sudo command"

Alias

/etc/ssh/ssh_config   # system-wide
~/.ssh/config         # per user (better)

# Add this in the config.
Host server_name
  Port 22
  User user
  HostName 123.456.789.255

# Connect with this now.
ssh server_name

SSH with RSA key

Access servers with a public/private key instead of a password. This is a much more secure method.

Transfer the public key id_rsa.pub to the remote server, in the ~/.ssh/authorized_keys file, with this command:

ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

If the keys don't exist on local machine, generate them:

ssh-keygen

# keys are stored in /home/user/.ssh
ls ~/.ssh

The private key id_rsa stays in the local machine.