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_nameThis is used to log in without writing the password each time. Also, it is much more secure.
Generate private/public keys in /home/user/.ssh
ssh-keygen
- Private key
id_rsastays in the host machine in~/.ssh. - Public key
id_rsa.pubgoes on the server in a~/.ssh/authorized_keysfile.
Simple as that, the next ssh is password-less.
To transfer a public key, use this:
ssh-copy-id user@255.255.255.255This automates the manual creation of an ~/.ssh/authorized_keys file and putting the id_rsa.pub key in.