sudo apt-get install openssh-serverssh -p PORT USER@SERVER_IP
# Execute one command and exit.
ssh -p PORT USER@SERVER_IP lsSSH 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 user@127.0.0.1# It will ask for the root password in the remote machine
ssh -t user@255.255.255.255 "sudo command"/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_nameAccess 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 user@123.456.789.255If the keys don't exist on local machine, generate them:
ssh-keygen
# keys are stored in /home/user/.ssh
ls ~/.sshThe private key id_rsa stays in the local machine.