How t setup SSH shortcut
By Pravin•
An SSH shortcut is an entry in your SSH config file. Once it's set up, you can connect by typing ssh myvm instead of the full command with the key, username and IP address.
1. Open (or create) the config file
- Mac / Linux:
~/.ssh/configmkdir -p ~/.ssh && nano ~/.ssh/config - Windows (PowerShell):
C:\Users\<you>\.ssh\config. Make sure the file has no extension: Notepad likes to save it asconfig.txt.notepad $HOME\.ssh\config
2. Add one block per VM
Host oci-vm1
HostName 152.67.xx.xx
User ubuntu
IdentityFile ~/.ssh/oci-vm1.key
IdentitiesOnly yes
ServerAliveInterval 60
Host oci-vm2
HostName 129.154.xx.xx
User opc
IdentityFile ~/.ssh/oci-vm2.key
IdentitiesOnly yes
ServerAliveInterval 60
- Host: the shortcut name you'll type. Pick anything you like.
- HostName: the VM's public IP, which you can find on the instance page in the OCI console.
- User: use
ubuntufor Ubuntu images andopcfor Oracle Linux. - IdentityFile: the private key you downloaded when you created the VM. On Windows you can write the path as
C:/Users/<you>/.ssh/oci-vm1.key. - ServerAliveInterval 60: keeps idle sessions from being dropped.
3. Fix the key permissions (Mac / Linux)
SSH refuses to use a key that other users can read, so run:
chmod 600 ~/.ssh/config ~/.ssh/*.key
4. Connect
ssh oci-vm1
The shortcut also works with file copying, for example scp file.txt oci-vm1:~/ or rsync -av folder/ oci-vm1:~/folder/. VS Code's Remote-SSH extension picks these entries up automatically.
If you get "Permission denied (publickey)", it's almost always one of two things: the username is wrong (ubuntu and opc are easy to mix up) or the key file permissions are too open (step 3).
Comments
No comments yet. Be the first to comment!
Leave a Comment
Your comment will be visible after approval.