Talk:OpenSSH
X11 forwarding
regarding X11 forwarding: i don't think it is necessary to enable X11Forwarding on the client on a global base: "Enable the ForwardX11 option in ssh_config on the client."
simply specifing -X option to ssh works for me. [The preceding unsigned comment was added 2010-01-11T15:41:54 by Uwinkelvos (Talk | contribs).]
Upon another look at the SSH Forwarding section, as per the comment in the Stack Exchange link provided [1] the xorg-xhost package is not needed on either the remote side or client side.
However the xorg-xauth package is needed on the side client for the ForwardX11Trusted
or -X
options to work.
Jamesp9 (talk) 10:56, 2 September 2017 (UTC)
- are you really sure 'xhost +si:localuser:user2' is not needed? -- Ubone (talk) 06:34, 5 July 2020 (UTC)
I have to use export DISPLAY=:10.0 on the server after logging in before I can actually run any programme requiring X. --cfr (talk) 22:25, 26 September 2017 (UTC)
SendEnv
I think we should add something about accent/UTF-8/encoding. Setting SendEnv LANG LC_* in /etc/ssh/ssh_config (client side) would be very useful. —This unsigned comment is by LeCrayonVert (talk) 22 August 2010. Please sign your posts with ~~~~!
Automatically logout all SSH users when the sshd daemon is shutdown.
edit /lib/systemd/system/systemd-user-sessions.service and append network.target to the after line.
[Unit]
Description = Permit User Sessions
Documentation = man:systemd-user-sessions.service(8)
After = network.target remote-fs.target
then symlink /lib/systemd/system/systemd-user-sessions.service to /etc/systemd/system/
artomason (talk) 20:32, 7 February 2013 (UTC)
systemd failed to start sshd
It might be good to add, if systemctl status sshd
shows that sshd failed, try and run /usr/sbin/sshd. This way if there is a bad configuration option (ie typo in /etc/ssh/sshd_conf), it is listed with line number.
Matyilona200 (talk) 13:45, 16 May 2013 (UTC)
follow_symlinks
The option 'transform_symlinks' does not work anymore, 'follow_symlinks' is the new one.
1. Should we correct that at the autossh section?
2. Should we write that somewhere?
--Greenway (talk) 17:14, 26 April 2014 (UTC)
- Are you sure? I've just installed sshfs and the man page still mentions both options as separate functions. If
transform_symlinks
is really not working anymore, that's more likely a bug that must be reported upstream. - Anyway I'm just mentioning that also the sshfs article would be affected.
- -- Kynikos (talk) 03:12, 28 April 2014 (UTC)
Sorry for this discussion and thank you for correcting me.
I referred to this question: http://askubuntu.com/questions/75094/sshfs-transform-symlinks-is-broken
Anyway I tested both parameters:
1) sshfs bar: foo -a --> /etc l -b --> c/c1 l -c d --c1 f 2) sshfs -o follow_symlinks bar: foo -a d -b d -c d --c1 f (works as expected) 3) sshfs -o transform_symlinks bar: foo (same as without the option.)
Here' s the wiki explanation
Following symlinks on the server side
The -o follow_symlinks option will enable this.
Making absolute symlinks work
Use the -o transform_symlinks option, which will transform absolute symlinks (ones which point somewhere inside the mount) into relative ones.
--Greenway (talk) 20:38, 28 April 2014 (UTC)
Regenerate host keys
I am using pre-load arch linux image on Raspberry Pi, which had openssh configured, so I want to regenerate new host keys, which could be archived on Debian with
rm /etc/ssh/ssh_host_* && dpkg-reconfigure openssh-server
Do we have equivalent command on Arch? I can't find them on the wiki
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
should be enough? Or more setting is required?
Ref:
Nowadays you'd also need to run ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
in addition to the three above.
Instead, you can just use ssh-keygen -A
to regenerate the keys, as long as there aren't any keys existing in /etc/ssh
. I wrote a handy script, if you need to do this a lot:
#!/bin/bash [ "$UID" -ne 0 ] && echo "Have to be root" && exit 1 read -p "Are you absolutely sure? (y/n )" -n 1 choice if [ "${choice,,}" = "y" ] then rm -v /etc/ssh/ssh_host_* ssh-keygen -A systemctl restart sshd fi
Tralce (talk) 19:11, 13 December 2021 (UTC)
- Why don't you just
rm /etc/ssh/ssh_host_*
andsystemctl restart sshd
?sshd.service
wantssshdgenkeys.service
which auto-generates all keys... — Lahwaacz (talk) 07:26, 16 December 2021 (UTC)
AutoSSH as a Service
AutoSSH doesn't like to run as a service without specifying a port. Using -M 0 and -f parameters in combination will result in the service not starting. Also, when starting as a service (-f option) SSH will not look in ~/.ssh for public keys. If you're using key authentication, the public key will need to be specified with the -i parameter. I assume this limitation would also apply when running as a systemd service.
Running AutoSSH this way worked for me for a Socks 5 proxy:
autossh -f -M 1111 -N -i /home/username/.ssh/id_rsa username@server -D 8080
--Twofive0 (talk) 18:24, 12 August 2014 (UTC)
- Autossh as a service seems to be a little redundant, since autossh itself is basically just a service to restart ssh when it exits. I was about write a .service file for autossh when I realized I could cut out the middleman entirely:
~/.config/systemd/user/autossh.service
[Unit] Description=SSH tunnel [Service] Type=simple Restart=always RestartSec=1min ExecStart=/usr/bin/ssh -F %h/.ssh/config -N foo@bar [Install] WantedBy=default.target
- This seems a little nicer to me, but I'm not sure how I would edit the article to include it.
- Silverhammermba (talk) 00:32, 12 February 2015 (UTC)
Additional steps to setup Dropbear
Noticed that you need to create some keys before Dropbear will run:
dropbearkey -t dss -f /etc/dropbear/dropbear.dss dropbearkey -t rsa -s 4096 -f /etc/dropbear/dropbear.rsa
Maybe it's a good idea to chmod this to 600 or something? —This unsigned comment is by MindTooth (talk) 5 December 2014. Please sign your posts with ~~~~!
- To note: Not relating to dropbear, but generally #Regenerate_host_keys above suggests the addition of a setup step for that as well. --Indigo (talk) 14:19, 5 December 2014 (UTC)
Allowing SSH Users to Shutdown, Mount, etc. Without Root authentication
- Merged from Allow users to shutdown. -- Alad (talk) 20:48, 23 May 2015 (UTC)
The following describes what I did to allow power [EDIT: and mounting] operations on my machine from a SSH login. I'd be very grateful if anyone could tell me if this was correct and if so, I'll add this section to the page and add a link on the polkit examples.
I have a miniature server machine I use at home for automatic backups, and I used WOL to startup without user intervention, however I found out that issuing
systemctl poweroff
and friends works from a tty but from a remote login I get a message starting:
==== AUTHENTICATING FOR org.freedesktop.login1.power-off ====
and asking for a root password. After searching online it seemed that the right thing to do (but I'm not sure) was to write a polkit rule overriding the and place this before the defaults in /etc/polkit-1/rules.d/. Below is my rule:
polkit.addRule(function(action, subject) { if ( action.id == "org.freedesktop.login1.power-off" || action.id == "org.freedesktop.login1.power-off-multiple-sessions" || action.id == "org.freedesktop.login1.reboot" || action.id == "org.freedesktop.login1.reboot-multiple-sessions" || action.id == "org.freedesktop.login1.suspend" || action.id == "org.freedesktop.login1.suspend-multiple-sessions" || action.id == "org.freedesktop.login1.hibernate" || action.id == "org.freedesktop.login1.hibernate-multiple-sessions" ) { if ( subject.isInGroup("mypowergroup") ){ return polkit.Result.YES; } });
There might be a neater way to do this rather than enumerating all the actions but I don't speak JavaScript. EDIT: See below:
https://gist.github.com/wooptoo/4013294/ccacedd69d54de7f2fd5881b546d5192d6a2bddb
Someone somewhere seemed to mention that polkit rules weren't the right way to go and there was something wrong with integration with logind/systemd but I didn't understand what he really meant and it was in a different context.
Thanks in advance for any advice --Stellarpower (talk) 12:24, 4 May 2015 (UTC)
Pseudo-terminal will not be allocated because stdin is not a terminal
When you connect to a ssh server via a ssh relay using command like:
ssh user2@relay ssh user3@localhost -p 2222
without -t
, you will get errors like this:
Pseudo-terminal will not be allocated because stdin is not a terminal. Host key verification failed.
Because, without -t
, ssh is not going to allocate a tty for command ssh user3@localhost -p 2222
. ssh(1)
Basically, if you want to execute a command which needs interactions, you need add -t
.
For eamlple:
ssh -t user@server "tmux"
If you just execute a command which just outputs and doesn't need interactions, you could just omit the -t
.
For example:
ssh user@server "echo test"
—This unsigned comment is by Edward-p (talk) 12:59, 13 July 2019. Please sign your posts with ~~~~!
- Thanks, but the flag is about a different command. -- Lahwaacz (talk) 13:21, 13 July 2019 (UTC)
sshd.socket warnings
The warning list at OpenSSH#Daemon_management reads like FUD to me. The warnings are not constructive, they look like they are designed to scare people away.
Examples:
- Warning: If you continue using
sshd.socket
, be aware of its issues:- This doesn't read well to a new person. They are not "continuing" to use anything. It's basically aimed at existing users.
- Labels socket activation as "having issues".
- Warning: Using
sshd.socket
negates theListenAddress
setting, so it will allow connections over any address. To achieve the effect of settingListenAddress
, you must specify the port and IP forListenStream
(e.g.ListenStream=192.168.1.100:22
) by editingsshd.socket
. You must also addFreeBind=true
under[Socket]
or else setting the IP address will have the same drawback as settingListenAddress
: the socket will fail to start if the network is not up in time.- Not constructive.
sshd.service
also listens on0.0.0.0
and[::]
by default, there is no difference. It sounds like this behavior is an "issue" withsshd.socket
.- This criticism could rather have been pointed out as a paragraph or a tip:
- Warning: When using socket activation a transient instance of
sshd@.service
will be started for each connection (with different instance names). Therefore, neithersshd.socket
nor the daemon's regularsshd.service
allow to monitor connection attempts in the log. The logs of socket-activated instances of SSH can be seen withjournalctl -u "sshd@*"
or withjournalctl /usr/bin/sshd
.- This is a quite negative perspective.
- It's not true:
sshd.socket
orsshd.service
don't disallow monitoring connection attempts in the log. I'm not quite sure what that statement even means. Everything is certainly logged, regardless of whethersshd.service
orsshd.socket
is used. - This could suffice: Tip: To views logs of
sshd.socket
activated instances, run for examplejournalctl /usr/bin/sshd
It comes off as an attack on socket activation IMO, and while socket activation might not be wanted by everyone, it's certainly a valid thing to use:
- http://0pointer.de/blog/projects/systemd.html
- http://0pointer.de/blog/projects/socket-activation.html
- Improving_performance/Boot_process#Early_start_for_services
Does anybody else agree on it being overly negative? Should we change it to make it constructive?
Aude (talk) 11:43, 3 October 2019 (UTC)
- As you correctly guessed the warning is aimed at existing not new users. New users would not have
sshd.socket
andsshd@.service
since they were removed from the openssh package. - The criticism of placing it all in a Template:Warning is warranted, as previously it was split between a warning, note and tip. I rationalized it with the thought that after a while that whole warning could just be removed. I have now split them again, though differently than before.
- There should be no issue if you want to make the section less scary, but keep in mind that it must be made clear that
sshd.socket
is not supported by Arch and users are on their own if they use it. - -- nl6720 (talk) 12:06, 3 October 2019 (UTC)
- That makes sense, I understand the rationale:
sshd.socket
is deprecated. - The split you did now reads much better IMO.
- What do you think about moving the
sshd.socket
related stuff down to OpenSSH#Tips_and_tricks? I'm thinking it could make sense to move information about a deprecated feature out of the main information, to reduce noise. - Aude (talk) 08:53, 4 October 2019 (UTC)
- That makes sense, I understand the rationale:
- You may move it to OpenSSH#Tips and tricks, but then you should add example units or link to sshd.socket & sshd@.service. Also the first note must stay in OpenSSH#Daemon management. -- nl6720 (talk) 09:52, 4 October 2019 (UTC)
- Okay, sounds good. I might do it. Aude (talk) 15:31, 5 October 2019 (UTC)
- Pointing out certain issues is not an attack on anything. I also don't think that the current wording is overly negative - certainly not more negative than the existence of the issues. -- Lahwaacz (talk) 18:56, 3 October 2019 (UTC)
/etc/ssh/sshd_config
I added a critical security warning not to bind sshd to ports above 1024, but it was rolled back right after my edit. I have some more edits I'd make to the section, but I'll hold off if my contributions aren't welcome. Some things I'd address, in addition to general re-wording for clarity:
- The current section gives a "random" port that a non-root user could bind an arbitrary service to. It shouldn't be higher than 1024, as only root can bind to ports lower than that. If the sshd service failed to start for any reason (like mis-configuration), a malicious user could bind their own service to a port and pretend to be the sshd service if the port is higher than 1024. This is very bad.
- The example of specifying a HostKey in the config uses rsa, but someone new to configuring this should probably see an example that uses ecdsa or ed25519 in case they follow the example.
- The advice to disable passwords entirely should be more prominent, and mention that it should be enabled only long enough to copy over an authorized key.
- The tip about listening to multiple ports is totally fine, but not really relevant to a section that should have some dense explanation of best practices in the first place someone looks when configuring sshd.
Szed (talk) 06:25, 1 December 2019 (UTC)
- Making significant changes to a critical page about security should always be discussed first. Your edit about ports >1024 was unsupported by any documentation. It is essentially FUD, as per https://security.stackexchange.com/questions/112072/risk-of-running-services-on-ports-1024 If you have got an authoratitive source, please incude it here. Jasonwryan (talk) 06:34, 1 December 2019 (UTC)
- Apologies, I'm new here and didn't mean to jump the gun on the edit. I am making the assumption that only ports up to 1024 are privileged on Arch as with other systems, but if that is indeed the case, an explanation of what that means is laid out in simple terms here https://www.w3.org/Daemon/User/Installation/PrivilegedPorts.html and further explanation here is more a comprehensive answer: https://stackoverflow.com/questions/10182798/why-are-ports-below-1024-privileged. These are all marginal risks; while running sshd on an unprivileged port certainly doesn't suddenly make a machine "hackable", neither does leaving it running on port 22, and an unprivileged port is a more appreciable risk to someone who is e.g. opening sshd on a desktop machine running other software like a web browser (which could therefore bind to the unprivileged port and pretend to be the sshd server). Szed (talk) 06:57, 1 December 2019 (UTC)
- I get the distinction between {,non-}privileged. What I was looking for was an authoratitive analysis of the risk around >1024 and how it is definitively "a bad thing". Jasonwryan (talk) 07:06, 1 December 2019 (UTC)
- See RFC 7605 - Recommendations on Using Assigned Transport Port Numbers at https://tools.ietf.org/html/rfc7605. Details (though not particularly relevant) on how SSH received 22 at https://www.ssh.com/ssh/port. I'm not sure I can easily provide you an authoritative reference vis-a-vis the specific risk of running sshd on a port >1024, except to say there's no reason for privileged ports to exist besides this. Szed (talk) 07:23, 1 December 2019 (UTC)
- After finally getting a change to review some more on this subject, I agree it isn't a big security issue worth concerning anyone over, though I do still think its important to add a note about the need to ensure the sshd service starts properly before allowing connections thought the firewall. Any feedback on my adding a note about using sshd -t to test that the config file throws no errors before enabling? Szed (talk) 00:50, 6 December 2019 (UTC)
- I don't see how
sshd -t
relates to unprivileged ports... -- Lahwaacz (talk) 15:16, 7 December 2019 (UTC)
- I don't see how
- I'm sorry to hear that. Szed (talk) 19:01, 7 December 2019 (UTC)
suggestion: using test mode to avoid failed service on unprivileged port
Here's my proposed addition, at the top near the first mention of sshd_config, instead of making any mention of risks associated with failed services from this port conversation. Szed (talk) 01:22, 6 December 2019 (UTC)
After editing this file, use test mode to check the configuration for errors:
# sshd -t
If no errors are printed, the configuration is valid.
- This looks like a good addition Jasonwryan (talk) 02:15, 13 December 2019 (UTC)
- Done. Thoughts on if its worth my trying to clean up the section generally? A lot of the example configuration lines are really tips and tricks, while there's a (very) short list of things that should be mentioned to every new user: (1) keeping root login disabled; (2) adding a public key from a client machine; (3) disabling password login; (4) checking the fingerprint signature to compare against when a client connects for the first time... ssh-keygen -lf if I remember correctly Szed (talk) 00:59, 18 December 2019 (UTC)
disable known weak algorithms and ciphers
This is the currently listed order of algorithms recommended "disable known weak algorithms and ciphers" for this page.
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group14-sha256,diffie-hellman-group18-sha512 MACs umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com HostKeyAlgorithms ssh-rsa,rsa-sha2-256,rsa-sha2-512
This does not reflect the security recommendations of the developers of OpenSSH, which can be found at https://man.openbsd.org/sshd_config. In particular, the HostKeyAlgorithms suggested here makes the least secure option the preferred first selection.Here are the orders from the default install's sshd_config in OpenBSD-current as of the OpenSSH 8.1 release, which I am using to update the wiki now:
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1 MACs umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 HostKeyAlgorithms ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
Szed (talk) 00:45, 6 December 2019 (UTC)
- So you just copy-pasted the values from the OpenBSD's man page (which is the same as the one in Arch: sshd_config(5)). This goes completely against the point of the section (first sentence): "The package's default configuration allows known weak algorithms and ciphers [...]" If the sentence is wrong/outdated, the whole section should be just removed. -- Lahwaacz (talk) 15:12, 7 December 2019 (UTC)
- "OpenSSH only disables algorithms that we actively recommend against using because they are known to be weak." via source: https://www.openssh.com/legacy.html. Sounds like you should delete the whole section then. Szed (talk) 19:01, 7 December 2019 (UTC)
Removing unmaintained package references
PAM shield is no longer maintained according to the old lead developer: https://github.com/jtniehof/pam_shield/issues/16
I suggest that this link gets removed as it's dangerous to reference old software as a solution to a security problem.
Torxed (talk) 14:08, 20 December 2020 (UTC)
Fix for failure to start sshd.service on boot?
I use sshd on my desktop to access it from other home computers, so locally only. The following is my config:
/etc/sshd/sshd_config.d/10-local_only.conf
PermitRootLogin no PasswordAuthentication no PubkeyAuthentication no ListenAddress 192.168.1.2 Match Address 192.168.1.* PubkeyAuthentication yes AllowUsers username
Feel free to pick that apart, but I digress. sshd.service
was enabled but would not start on boot, instead giving the error that it could not bind to the IP address, which makes sense because it's not yet available.
I found this reddit comment that suggests the following:
- If the
ListenAddress
default of 0.0.0.0 is changed insshd_config
to point to an IP other than your main one, then it won't load on boot because that interface isn't ready yet.
- The fix is the sysctl setting
net.ipv4.ip_nonlocal_bind = 1
, which allows things (like sshd) to listen on IPs that aren't available yet.
- ArchLinux doesn't use
/etc/sysctl.conf
, so you need to put that in/etc/sysctl.d/99-sysctl.conf
then sshd will start on boot.
I tried this solution and it worked for me, but I did not want to add it to this page without allowing others to vet it. — Zosoled (talk) 05:58, 24 July 2024 (UTC)
Never a good idea to suggest passwords in plaintext?
A thought on OpenSSH#Alternative service should SSH daemon fail, should this be changed to something like dropbear or something? It wouldn't be hard to make sure that dropbear and OpenSSH had the same key even. You can of course set up a TLS-protected telnetd, but what's here now kind of suggests falling back on a default-unencrypted telnet, which is obviously not great advice.
A more robust solution might be a rescue environment involving a few statically-compiled tools (sash, busybox, dropbear?) but it doesn't look like that's something anyone has sought to wiki yet. If they do, a reference here to it might not go amiss. Knghtbrd (talk) 06:40, 27 September 2024 (UTC)