Tutorial to connect your server with ssh alias
This tutorial show you how to ssh to your server without rememering the server’s ip
ssh your_server
1. ssh-keygen
Create an ssh private/public keypair.
Here I named my key personal. Do replace yours.
For passwordless experience, let passphrase be empty.
cd $HOME/.ssh
ssh-keygen -t rsa
2. Copy public key to server
You can manully copy the public key or use the command for that
2.1. Manually copy
- Print and copy your public key
cat ~/.ssh/personal.pub
On your server, pass the public key to the end of $HOME/.ssh/authorized_keys
2.2. Use ssh-copy-id
- Copy the public key to server
- My server ip is
192.168.1.111
. Do replace with yours.
ssh-copy-id -i personal root@192.168.1.111
- Chmod server’s ssh files permission for security (optinal)
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
service ssh restart
- Try login by password
ssh 'root@192.168.1.111'
Hura! Now we can connect to server through ssh. Next, let’s create an alias for the server.
3. SSH Alias
- From your local machine, add these line to the end of
$HOME/.ssh/config
Host hp
HostName 192.168.1.111
User root
IdentityFile ~/.ssh/personal
- Replace
hp
,192.168.1.111
,root
,~/.ssh/personal
with your alias, ip, server user and the private key path
cd $HOME/.ssh
vi config
4. Test
Well done, you can ssh to your server using alias now!