Change ssh config
First cd to the ssh local dict with cd /etc/ssh
.
Then edit the config file by
sudo cp sshd_config sshd_config.bak
sudo nano sshd_config
In the sshd_config:
-
If want to change the ssh port, e.g. add the port 43922 to the server, then add the line:
Port 43922
Then restart the sshd service by
/etc/init.d/sshd restart
orservice sshd restart
. -
If want to login in the server only via rsa, then cancer the password-auth in sshd_config:
PasswordAuthentication no //yes改为no ChallengeResponseAuthentication no //yes改为no RSAAuthentication yes //去掉前面的注释 PubkeyAuthentication yes //去掉前面的注释 AuthorizedKeysFile .ssh/authorized_keys //去掉前面的注释
Then restart the sshd service.
Generate ssh rsa key
Cd to the ssh local dict, and then generate the ssh rsa files. After that, copy the id_rsa.pub to the server.
Attention: You may need to change the port number if the ssh port is not default as 22.
ssh-keygen -t rsa
ssh-copy-id user@192.168.xxx.xxx -p 22