First try ssh localhost
ssh localhost
If the SSH service is not started, the following error will be reported:
ssh: connect to host localhost port 22: connection refused
Set SSH password-free login (optional)
This step sets the password-free login by setting the public and private keys. You can skip this step if the server is logged in with a username and password.
Running the following command generates a bunch of keys id_rsa and id_rsa.pub in the ~/.ssh/directory:
ssh-keygen
To enter the following prompt information, the key pair will be generated in the default location ~/.ssh/directory, and we set passphrase to empty, that is, no password login.
Use the following command to join the newly generated public key to the authorized key list file Authorized_keys (because there is no Authorized_keys file at the beginning, so use the CP command here):
cp ~/.ssh/id_isa.pub ~/.ssh/authorized_keys
Make sure that the. SSH directory and the Authorized_keys file have only the user's own Write permission, otherwise the validation is not valid
chomd 600 ~/.ssh/authorized_keyschmod 700 ~/.ssh
Open SSH Service
Configure the non-secret login still cannot ssh localhost, because Ubuntu default does not install and open the SSH server, therefore, we also need:
1. Determine the installation of sshd
sudo apt-get install openssh-server
2. Start sshd
sudo net start sshd
3. Check the firewall settings and turn off the firewall
sudo nfw disable
4. Verify the success, run the following command
ssh localhost
Sometimes although successful, but still will appear connection refused problem, this is, need to check whether the sshd process is started.
Run the following command to see if there is an sshd process:
ps -e | grep ssh
Sometimes although you can see the sshd, but still cannot connect successfully, this is the need to restart SSH:
sudo service ssh restart
Then connect again.
Ubuntu Config SSH service