SSH Setup
When you create a new user in linux, and you have to login as the new user say
ssh deploy@surajg.tech
To be able to do this, perform the following steps:
- Install openssh-server
sudo apt update
sudo apt install openssh-server
- Configure SSH server
sudo nano /etc/ssh/sshd_config
- Port: By default, SSH uses port 22. You can change this port if desired, especially for security reasons.
- Permit Root Login: It's generally recommended to disable remote root login for security purposes. You can set this option to
no. - Password Authentication: You may choose to allow or disallow password authentication for SSH. Disabling password authentication and using SSH keys instead is generally more secure.
- Allow Users/Allow Groups: You can specify which users or groups are allowed to connect via SSH.
- Restart SSH Service
Allow SSH Through Firewall
sudo ufw allow
ssh sudo ufw enable
Open /etc/ssh/sshd_config
- Add the following lines:
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
- Create a folder
mkdir -p ~/.ssh
- Paste your public key in your machine
sudo nano ~/.ssh/authorized_keys
- To ensure right syntax
cat /usr/sbin/sshd -t
- Ensure that the
.sshdirectory and theauthorized_keysfile have the correct permissions. The.sshdirectory should have permissions700, and theauthorized_keysfile should have permissions600. You can set these permissions using thechmodcommand.