Yu-Chieh’s Blog (Y.C. Chang)

Ruby on Rails / Rubygems / FullStack / Git / Mac notes.

How to Setup for Ssh Connet to Vps Server

  • use ssh-keygen to generate keys (public/private)
1
$ ssh-keygen -t rsa # -t refers to key type, here we use rsa
  • The keys were generated under ~./ssh folder
  • copy public key to vps server
1
2
$ cd ~/.ssh
$ cat id_rsa.pub
  • Sign in vps server
  • Before we use ssh to connect vps, we have to activate ssh service for ssh connection.
1
2
3
4
5
6
7
$ sudo apt-get install openssh-server # make sure your server install openssh service (here we use ubuntu)
$ sudo pico /etc/ssh/sshd_config # edit sshd setting
# Port 12141 # do not forget to change port for security reason
# PermitRootLogin yes --> PermitRootLogin no # for disable root ssh login 
$ sudo /etc/init.d/ssh restart # restart sshd
# or use service tool
$ service ssh restart
  • put your public key to vps
1
2
3
$ mkdir .ssh
$ touch authorized_keys
# then copy your local ~/.ssh/id_rsa.pub to authorized_keys by any text editor (vi,pico...etc)
  • On Mac, we can use ‘ssh-copy-id’ to install our identity.pub in a remote machine’s authorized_keys.
  • Now, you can ssh to connect your vps directly without typing any password.
  • enjoy.

Comments