Ssh
Installing SSH
Make sure you have openssh-client installed you might already have it installed if not do
sudo apt install ospenssh-client
to install openssh-server do
sudo apt install openssh-server
- Check open ports/ if active
Configuring SSH Server
You need to edit the file located in /etc/ssh/sshd_config
you can either cd into each directory until you get to the file or simply do
sudo vim /etc/ssh/sshd_config
You will want to change the default port to something else besides 22 you can do this by removing the # and entering the number you want
Change PermitRootLogin prohibit-password
→ PermitRootLogin no
You can choose to allow only users you specify by adding AllowUsers (user)
at the end of the file
You can do groups instead if you'd like by doing AllowGroups (group)
To add a user to that group do sudo usermod -aG (group) (user)
the -a
to add and the -G
is used for secondary group to change a users primary group do just -g
.
To create groups do
sudo groupadd (groupname)
To delete a group do
sudo groupdel (groupname)
Public Key Authentication
To generate a new key do
ssh-keygen
Two new files will be created in .ssh id_rsa
and id_rsa.pub
In order to create a public key relationship between two systems do
ssh-copy-id -p(port) -i ~/.ssh/id_rsa.pub (ip)
once the key is copied over a new file called authorized keys
should appear under .ssh
on the second machine.
You can turn PasswordAuthentication no
in config file
Troubleshooting SSH
First ask person that is ssh'ing into the server to add -v
which is verbose. (client side)
ssh -v user@host
If you want to see logs in Ubuntu/Debianon your side do (server side)
cat /var/log/auth.log
If you want to see the last 10 lines of log file do
tail /var/log/auth.log
If you want too see log in real time do
tail -f /var/log/auth.log