Config Files
~/.ssh/*, /etc/ssh/ssh_config, and /etc/ssh/sshd_config
There are no required changes to any of these files. However, you
may wish to view the /etc/ssh/
files and make any changes appropriate for the security of your
system. One recommended change is that you disable root login via ssh. Execute the following
command as the root user to
disable root login via
ssh:
echo "PermitRootLogin no" >> /etc/ssh/sshd_config
If you want to be able to log in without typing in your password,
first create ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub with
ssh-keygen and then
copy ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys on the remote
computer that you want to log into. You'll need to change
REMOTE_USERNAME and REMOTE_HOSTNAME for the username and hostname
of the remote computer and you'll also need to enter your
password for the ssh-copy-id command to succeed:
ssh-keygen &&
ssh-copy-id -i ~/.ssh/id_ed25519.pub REMOTE_USERNAME@REMOTE_HOSTNAME
Once you've got passwordless logins working it's actually more
secure than logging in with a password (as the private key is
much longer than most people's passwords). If you would like to
now disable password logins, as the root user:
echo "PasswordAuthentication no" >> /etc/ssh/sshd_config &&
echo "KbdInteractiveAuthentication no" >> /etc/ssh/sshd_config
If you added Linux-PAM support
and you want ssh to use it then you will need to add a
configuration file for sshd and
enable use of LinuxPAM. Note,
ssh only uses PAM to check passwords, if you've disabled password
logins these commands are not needed. If you want to use PAM,
issue the following commands as the root user:
sed 's@d/login@d/sshd@g' /etc/pam.d/login > /etc/pam.d/sshd &&
chmod 644 /etc/pam.d/sshd &&
echo "UsePAM yes" >> /etc/ssh/sshd_config
Additional configuration information can be found in the man
pages for sshd,
ssh and
ssh-agent.
Systemd Unit
To start the SSH server at system boot, install the sshd.service unit included in the blfs-systemd-units-20261022 package.
Note
Changing the setting of ListenAddress in /etc/sshd/sshd_config is unsupported with the
BLFS sshd systemd unit.
make install-sshd
You can then enable the unit at startup as the root user with:
systemctl enable sshd
Note
This package comes with two types of units: A service file and
a socket file. The service file will start sshd daemon once at
boot and it will keep running until the system shuts down. The
socket file will make systemd listen on ssh port (Default 22,
needs to be edited for anything else) and will start sshd
daemon when something tries to connect to that port and stop
the daemon when the connection is terminated. This is called
socket activation and is analogous to using {,x}inetd on a SysVinit based system.
With the above command, the first method is used - sshd daemon
is started at boot and stopped at shutdown. If the socket
method is desired, you need to run instead (as the root user):
systemctl enable sshd.socket