date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,635,063,773,000 |
NB: The OpenSSH clients I am using are all at version 7.2, so no RemoteCommand available.
Assume the following setting:
machine foo is a jump host and provides access to host bar via its localhost:10022
bar sits inside a network inside of which we can access host rdp and access its RDP port (3389). I actually give the IP of rdp inside my command lines and configuration, but I presume that it is legit to use its name as long as name lookup works. For brevity I am using rdp here.
The goal is now to gain access to rdp:3389 by connecting to bar via jump host foo and forward that to localhost:33389 on the local machine from which I am invoking ssh bar.
[local:33389] --> {foo} --> {bar} --> [rdp:3389]
Interlude
I have solved this previously with PuTTY as follows:
create a connection to foo and configure a local forwarding -L 33389:localhost:33389, thus tying localhost:33389 on the local machine to localhost:33389 on foo.
use the following remote command to carry the port forwarding into the network inside of which bar sits by passing ssh -L 33389:rdp:3389 -A bar.
Host bar is configured on foo inside of .ssh/config to connect to localhost:10022 and thereby end up on bar via the jump host.
The PuTTY configuration works like a charm, but it relies on a remote command to be executed. While a shell alias would be one way of going about this, I was wondering if there's a way to keep everything inside the ssh_config(5) used by my client, using ProxyCommand?
A rough equivalent of the above PuTTY configuration is this:
ssh -L 33389:localhost:33389 foo ssh -t -L 33389:rdp:3389 -p 10022 localhost
or, provided that Host bar is configured on foo to go through localhost:10022 of foo:
ssh -L 33389:localhost:33389 foo ssh -t -L 33389:rdp:3389 bar
And this seems to get the job done.
But of course this is plenty to type and it would be neater to be able to put this all into the configuration file and simply type ssh bar on the local machine.
With RemoteCommand as introduced in OpenSSH 7.6 this seems to be rather trivial:
Host bar
HostName foo
RemoteCommand ssh -L 33389:rdp:3389 -A -p 10022 localhost
LocalForward 33389 localhost:33389
... which should roughly translate to the ssh invocation shown above. But as mentioned before, I am using an older (packaged) version of OpenSSH without support for the RemoteCommand stanza.
Here's the attempt that seems to come closest to what I want to achieve.
Host bar
HostName localhost
Port 10022
ProxyCommand ssh -L 33389:localhost:33389 -W %h:%p foo
LocalForward 33389 rdp:3389
The idea being that on the local machine I will simply invoke ssh bar. In fact it works in that I end up on the shell prompt of bar, but the port forwarding doesn't work at all. While sudo lsof -i|grep 3389 on the local machine gives me:
ssh 15271 accden 6u IPv6 7933201 0t0 TCP localhost:33389 (LISTEN)
ssh 15271 accden 7u IPv4 7933202 0t0 TCP localhost:33389 (LISTEN)
On the jump host I see nothing listening on any port containing 3389.
Since ProxyCommand establishes the connection to foo and I am giving a LocalForward for the connection to bar, I'd expect this to work.
What am I doing wrong?
Goal is to use ssh bar to connect to bar and at the same time make rdp:3389 available on the local machine as localhost:33389. Tweaking the ssh_config(5) files on the local machine and foo are allowed. Passing remote commands is not a valid answer, though.
|
First, with your kind of setting, what would work, requiring anyway two ssh:
Host foo
LocalForward 10022:bar:22
Host bar
Hostname localhost
Port 10022
LocalForward 33389 rdp:3389
term1$ ssh foo # or use ssh -f -N -o ExitOnForwardFailure=yes foo for background task
term2$ ssh bar
What you'd really need wouldn't be RemoteCommand but ProxyJump, really simplifying your configuration, with goal reached only with:
ssh -L 33389:rdp:3389 -J foo bar
Or the equivalent (only) configuration:
Host bar
ProxyJump foo
LocalForward 33389 rdp:3389
With zero intermediate port needed.
Unfortunately ProxyJump is available only starting from openssh 7.3
But it's easily replaced with the ProxyCommand/-W combo you were using before.
ssh -L 33389:rdp:3389 -o 'ProxyCommand=ssh foo -W %h:%p' bar
or as configuration file:
Host bar
ProxyCommand ssh -W %h:%p foo
LocalForward 33389 rdp:3389
There are still two ssh running: the hidden one is the one as ProxyCommand parameter still running on the local host doing the link using a pair of pipes with the main ssh, instead of an extra tcp port. Trying to involve the intermediate host in participating with the port forwarding is insecure or can clash (other users of foo can access the tunnel or use the same port), and prone to errors. Tunnel ends should always be kept on the client host if possible, where there's full control. Intermediate tunnels should either not exist or point to the next ssh entry point (that's the -W 's usage here).
| SSH port forwarding via jump host, ssh_config files and ONLY "ssh targethost" |
1,635,063,773,000 |
Before I can to connect to a particular remote machine I have to run a certain local command. So instead of ssh [email protected] I have to do
local_command
ssh [email protected]
I would like to automate this so that I only have to do ssh remote.machine.
I know that I can achieve this at the shell level by creating my own ssh script that calls /usr/bin/ssh, but can I do it using the ProxyCommand option of ssh_config?
As far as I understand it, I need something like
Host remote.machine
ProxyCommand local_command; ssh [email protected]
in my ~/.ssh/config file, but not exactly this of course because it's circular!
|
If using ProxyCommand, you must use something like /usr/bin/nc to connect the server.
For invoking your command before connect, you need to use sh -c "command list" to merge the two commands as one.
Host remote.machine
ProxyCommand sh -c "local_command; /usr/bin/nc %h %p"
MORE:
If your local_command is too complicated, you can use a script:
cat my_connect.sh
#!/bin/bash
local_command
/usr/bin/nc "$1" "$2"
The ssh config becomes:
Host remote.machine
ProxyCommand /path_to_my_connect.sh %h %p
At the last, you can add your own proxy to the /usr/bin/nc
| Can ssh_config's ProxyCommand run a local command before connecting to a remote machine? |
1,635,063,773,000 |
After updating raspbian and all of its libraries I noticed something different about SSH. When I delete the 'known hosts' file in my home and ssh into my box it provides me with the hosts public key like always however this time I see:
ecdsa-sha2-nistp256 SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I swear it always gave me an RSA key type a few months back. Why did this change and how does the server decide which public key fingerprint from /etc/ssh/ to give the user connecting?
ssh --version on client linux mint 18 machine outputs OpenSSH_7.2p2 Ubuntu-4ubuntu1, OpenSSL 1.0.2g-fips 1 Mar 2016 and host outputs OpenSSH_6.7p1 Raspbian-5+deb8u3, OpenSSL 1.0.1t 3 May 2016
|
The client can specify the hostkey algorithm it prefers with the option HostKeyAlgorithms in ssh_config or ~/.ssh/config or on the command line. man ssh_config on your system to see the default HostKeyAlgorithms preference for your version of openssh. The server will use the first key type which is on the client's list and exists on the server.
If you would prefer to keep the old RSA key challenge, add
"-oHostKeyAlgorithms=ssh-rsa" to the command line, or add the line
HostKeyAlgorithms ssh-rsa
to your ssh configuration file(s).
| How does OpenSSH determine the choose the host key algorithm? |
1,635,063,773,000 |
I have a script that relies on public/private key ssh authentication. The problem is that some systems are misconfigured and do not have the proper ssh public/private key trust set up. When that happens ssh ask me for a password blocking the script's execution. I have tried this command:
sudo ssh -o "PasswordAuthentication=no" -o "ChallengeResponseAuthentication=no" root@last-call
But I still get prompted for the root password.
|
The canonical way to do this is with the BatchMode option:
ssh -o BatchMode=yes …
According to the manual:
If set to “yes”, passphrase/password querying will be disabled. This option is useful in scripts and other batch jobs where no user is present to supply the password.
I would have expected the combination of PasswordAuthentication=no and ChallengeResponseAuthentication=no to be enough though. ssh -vv might yield a clue.
| How to disable password prompt from ssh client side? |
1,635,063,773,000 |
I have been using PKI based SSH connections for over 10 years. Suddenly, after a server update - some of the connections stopped working. I am using the same PKI keys I have used for years (each server has it's own keys, I have a small set of personal keys).
Working - looks like this:
C:\Users\michael>ssh2 -p 2222 [email protected] date
Authentication successful.
Fri Nov 25 10:30:42 2016
Not working looks like:
C:\Users\michael>ssh2 [email protected] date
warning: Authentication failed.
Disconnected; key exchange or algorithm negotiation failed (Algorithm negotiation failed.).
What changed?
|
After an update - side-effects may come into play. With OpenSSH - defaults change frequently. OpenBSD (who maintain/develop OpenSSH) have a policy of OpenBSD to not be concerned about backwards compatibility. This can 'break' things that are, read were, working well.
There is a massive hint - that I did not notice when this first happened to me (using the GUI interface, and I just clicked it away and 'was angry' with 'stupid update - new version is broken'. Turns out the new version was not broken - but OpenBSD/OpenSSH starting changing the key exchange defaults starting with OpenSSH-6.7p1 see: http://www.openssh.com/txt/release-6.7, noteably:
Changes since OpenSSH 6.6
Potentially-incompatible changes
sshd(8): The default set of ciphers and MACs has been altered to
remove unsafe algorithms. In particular, CBC ciphers and arcfour*
are disabled by default.
The full set of algorithms remains available if configured
explicitly via the Ciphers and MACs sshd_config options.
My problem is I have an old client that does not have any of the new defaults, so it cannot connect.
Two solution paths: fix/patch the server or - fix/patch the client.
Server solution: bring back "old" settings so "old" clients can continue to connect that is, - friendly to existing clients - edit the sshd_config file and add back (enough) of the old ciphers.
The key lines to change/add in sshd_config being:
ciphers aes128-ctr,aes192-ctr,aes256-ctr,[email protected],aes256-cbc
KexAlgorithms [email protected],diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
macs hmac-sha2-256,hmac-sha2-512,hmac-sha1-96,hmac-sha1
Just add:
# Ciphers
# The dafaults starting with OpenSSH 6.7 are:
# aes128-ctr,aes192-ctr,aes256-ctr,[email protected]
# older clients may need an older cipher, e.g.
# ciphers aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,arcfour
# only adding aes256-cbc as an "old" cipher
ciphers aes128-ctr,aes192-ctr,aes256-ctr,[email protected],aes256-cbc
# KEX Key Exchange algorithms
# default from openssh 6.7 are:
# [email protected],diffie-hellman-group-exchange-sha256,\
# diffie-hellman-group14-sha1
# an older kex are: none,KexAlgorithms diffie-hellman-group1-sha1
# only adding diffie-hellman-group-sha1 as an "old" KEX
# and this should be deleted ASAP as it is clearly "one of the problems" with SSL based encryption
KexAlgorithms [email protected],diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
# MAC message authentification code
# the new defaults are:
# [email protected],[email protected],
# [email protected],hmac-sha2-512-
# [email protected],
# [email protected],[email protected],
# hmac-sha2-256,hmac-sha2-512
# older defaults (still supported) are:
# macs hmac-sha1,hmac-md5
# consider removing hmac-sha1-96,hmac-sha1,hmac-md5 "Soon!"
macs hmac-sha2-256,hmac-sha2-512,hmac-sha1-96,hmac-sha1
Solution #2 - fix/replace the client
An easy way to see what ciphers you current client supports (assuming CLI) is ssh -h and see if that provides something like:
Supported ciphers:
3des-cbc,aes256-cbc,aes192-cbc,aes128-cbc,blowfish-cbc,twofish-cbc,twofish256-cbc,twofish192-cbc,twofish128-cbc,[email protected],cast128-cbc,[email protected],arcfour,none
Supported MAC algorithms:
hmac-md5,hmac-md5-96,hmac-sha1,hmac-sha1-96,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],none
Another useful command is: ssh -V
ssh2: SSH Secure Shell 3.2.9 Windows Client
Product: SSH Secure Shell for Workstations
License type: none (non-commercial)
Mine - was - an very old client - for my desktop. Looking above you can see it does not support any of the - 15 years later - preferred algorithms, not even one -cbr (rotating), only -cbc (block-copy).
If you client does not have an option to provide the keys, etc. supported (OpenSSH should have the option -Q) just start a connection to yourself, e.g., ssh -v localhost and there are lines such as this to tell you wat is known:
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-grousha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected]@openssh.com,[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
...
And what was found (and used):
debug2: mac_setup: found hmac-sha1
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug2: mac_setup: found hmac-sha1
debug1: kex: client->server aes128-ctr hmac-sha1 none
Extra: debug info from a failed connect - more details
Or, what was tried, but missed.
debug: OpenSSH: Major: 7 Minor: 3 Revision: 0
debug: Ssh2Transport: All versions of OpenSSH handle kex guesses incorrectly.
debug: Ssh2Transport: Algorithm negotiation failed for c_to_s_cipher: client list: aes128-cbc,3des-cbc,twofish128-cbc,cast128-cbc,twofish-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,twofish192-cbc,twofish256-cbc,arcfour vs. server list : [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug: Ssh2Transport: Algorithm negotiation failed for s_to_c_cipher: client list: aes128-cbc,3des-cbc,twofish128-cbc,cast128-cbc,twofish-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,twofish192-cbc,twofish256-cbc,arcfour vs. server list : [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug: Ssh2Transport: lang s to c: `', lang c to s: `'
debug: Ssh2Transport: Couldn't agree on kex or hostkey alg. (chosen_kex = NULL, chosen_host_key = ssh-rsa)
debug: Ssh2Common: DISCONNECT received: Algorithm negotiation failed.
Edit: added 02-jan-2017
New Section - what about keys that stop working?
On my server I have an 'old' client and the 'latest' client installed - and get different behavior connecting to a server. Here the issue is not cipher mis-matches - but use of an archaic PKI pair - based on DSA.
In short, openssh-7(.3) no longer sends (by default, maybe not at all) DSA public keys.
Below I compare the output of two versions of openssh
/usr/bin/ssh (old version, left-side) and
/opt/bin/ssh (new version, right-side) - the command is:
${version}/ssh -v user@host date
As you scan through the output below I hope you notice the steps and messages are generally the same. The key difference comes after the string SSH2_MSG_SERVICE_ACCEPT
What I want you to notice is that the old version offers (and is accepted by the 'old' server - the DSA based key pair while the new server never offers the DSA based key.
Note: the 'solution' for this is to add (at least one of) the rsa, ecdsa, or the ed25519 based PKI pairs.
OpenSSH_6.0p1, OpenSSL 1.0.2h 3 May 2016 | OpenSSH_7.3p1, OpenSSL 1.0.2h 3 May 2016
debug1: Reading configuration data /etc/ssh/ssh_config | debug1: Reading configuration data /var/openssh/etc/ssh_confi
debug1: Failed dlopen: /usr/krb5/lib/libkrb5.a(libkrb5.a.so): <
0509-026 System error: A file or directory in the pat <
<
debug1: Error loading Kerberos, disabling Kerberos auth. <
debug1: Connecting to x061 [192.168.129.61] port 22. debug1: Connecting to x061 [192.168.129.61] port 22.
debug1: Connection established. debug1: Connection established.
debug1: identity file /home/michael/.ssh/id_rsa type 1 debug1: identity file /home/michael/.ssh/id_rsa type 1
> debug1: key_load_public: No such file or directory
debug1: identity file /home/michael/.ssh/id_rsa-cert type -1 debug1: identity file /home/michael/.ssh/id_rsa-cert type -1
debug1: identity file /home/michael/.ssh/id_dsa type 2 debug1: identity file /home/michael/.ssh/id_dsa type 2
> debug1: key_load_public: No such file or directory
debug1: identity file /home/michael/.ssh/id_dsa-cert type -1 debug1: identity file /home/michael/.ssh/id_dsa-cert type -1
debug1: identity file /home/michael/.ssh/id_ecdsa type 3 debug1: identity file /home/michael/.ssh/id_ecdsa type 3
> debug1: key_load_public: No such file or directory
debug1: identity file /home/michael/.ssh/id_ecdsa-cert type - debug1: identity file /home/michael/.ssh/id_ecdsa-cert type -
debug1: Remote protocol version 2.0, remote software version | debug1: key_load_public: No such file or directory
debug1: match: OpenSSH_6.0 pat OpenSSH* | debug1: identity file /home/michael/.ssh/id_ed25519 type -1
> debug1: key_load_public: No such file or directory
> debug1: identity file /home/michael/.ssh/id_ed25519-cert type
debug1: Enabling compatibility mode for protocol 2.0 debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0 | debug1: Local version string SSH-2.0-OpenSSH_7.3
> debug1: Remote protocol version 2.0, remote software version
> debug1: match: OpenSSH_6.0 pat OpenSSH* compat 0x04000000
> debug1: Authenticating to x061:22 as 'padmin'
debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none | debug1: kex: algorithm: ecdh-sha2-nistp256
debug1: kex: client->server aes128-ctr hmac-md5 none | debug1: kex: host key algorithm: ssh-rsa
> debug1: kex: server->client cipher: aes128-ctr MAC: umac-64@o
> debug1: kex: client->server cipher: aes128-ctr MAC: umac-64@o
debug1: sending SSH2_MSG_KEX_ECDH_INIT debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA 9f:0a:4d:a8:1b:ba:e6:d4:1a:b2:cd | debug1: Server host key: ssh-rsa SHA256:ORf5UVI7mRm/9MthM2qXM
debug1: Host 'x061' is known and matches the RSA host key. debug1: Host 'x061' is known and matches the RSA host key.
debug1: Found key in /home/michael/.ssh/known_hosts:57 debug1: Found key in /home/michael/.ssh/known_hosts:57
debug1: ssh_rsa_verify: signature correct | debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS debug1: expecting SSH2_MSG_NEWKEYS
> debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server | debug1: Skipping ssh-dss key /home/michael/.ssh/id_dsa - not
debug1: SSH2_MSG_SERVICE_REQUEST sent <
debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/michael/.ssh/id_rsa debug1: Offering RSA public key: /home/michael/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password debug1: Authentications that can continue: publickey,password
debug1: Offering DSA public key: /home/michael/.ssh/id_dsa | debug1: Offering ECDSA public key: /home/michael/.ssh/id_ecds
debug1: Server accepts key: pkalg ssh-dss blen 433 | debug1: Authentications that can continue: publickey,password
debug1: read PEM private key done: type DSA | debug1: Trying private key: /home/michael/.ssh/id_ed25519
debug1: Authentication succeeded (publickey). | debug1: Next authentication method: keyboard-interactive
Authenticated to x061 ([192.168.129.61]:22). | debug1: Authentications that can continue: publickey,password
debug1: channel 0: new [client-session] | debug1: Next authentication method: password
debug1: Requesting [email protected] | padmin@x061's password:
debug1: Entering interactive session. |
| SSH stopped working after a server update? What happened? |
1,635,063,773,000 |
Is there a more direct way to exit an OpenSSH control master process and delete its socket file than with the help of the programs lsof or fuser and without knowing the destination host (connection details) as suggested by the accepted answer of this question? I thought of something like this along the lines of:
$ ssh -O exit -S ~/.ssh/7eb92b0827f3e8e1e8591fb3d1a5cd1b94b758cb.socket
I'm asking because I'm looking for a scriptable way to exit every open control master connection each time when I log out of my user account. Not doing so causes my sytemd-powered openSUSE computer to wait for a timeout of two minutes until it forcefully terminates the still open control master connection powering off eventually.
Unfortunately OpenSSH's client program ssh requires the destination host and the ControlPath file name pattern in order to deduce the actual file path to the socket file. I on the contrary thought of the more direct method of providing the concrete socket file via the program's -S ctl_path option.
In the global section of my system-wide OpenSSH client config file I configured OpenSSH's connection multiplexing feature as follows:
ControlMaster auto
ControlPath ~/.ssh/%C.socket
ControlPersist 30m
Please note that I want to keep the file name pattern for socket files, i.e. hashing the token string %l%h%p%r with the token %C.
Any ideas?
|
This works for me using just the socket file for the control master:
$ ssh -o ControlPath=~/.ssh/<controlfile> -O check <bogus arg>
NOTE: You can also use ssh -S ~/.ssh/<controlfile> ... as well, which is a bit shorter form of the above.
Example
Here's an example where I've already established a connection to a remote server:
$ ssh -S ~/.ssh/master-57db26a0499dfd881986e23a2e4dd5c5c63e26c2 -O check blah
Master running (pid=89228)
$
And with it disconnected:
$ ssh -S ~/.ssh/master-66496a62823573e4760469df70e57ce4c15afd74 -O check blah
Control socket connect(/Users/user1/.ssh/master-66496a62823573e4760469df70e57ce4c15afd74): No such file or directory
$
If it were still connected, this would force it to exit immediately:
$ ssh -S ~/.ssh/master-66496a62823573e4760469df70e57ce4c15afd74 -O exit blah
Exit request sent.
$
It's unclear to me, but it would appear to potentially be a bug in ssh that it requires an additional argument at the end, even though blah is meaningless in the context of the switches I'm using.
Without it gives me this:
$ ssh -S ~/.ssh/master-57db26a0499dfd881986e23a2e4dd5c5c63e26c2 -O check
usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec]
[-O ctl_cmd] [-o option] [-p port]
[-Q cipher | cipher-auth | mac | kex | key]
[-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] [user@]hostname [command]
Version info
OSX
$ ssh -V
OpenSSH_6.9p1, LibreSSL 2.1.8
CentOS 7.x
$ ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
I confirmed that on both of these versions, the need for the additional bogus argument was required.
UPDATE #1
I raised this as a potential bug to the OpenSSH upstream and they replied as follows:
Yes - this is intentional.
ControlPath may contain %-expansions that need a hostname to expand fully.
We could conceivably check to see whether ControlPath actually needs this and make the hostname optional but 1) ControlPaths that use %h are common and 2) I'd rather not make the argument parsing code more of a maze than it already is.
References
How to tell if an ssh ControlMaster connection is in use
How to close (kill) ssh ControlMaster connections manually
| How to exit OpenSSH control master process without using lsof or fuser? |
1,635,063,773,000 |
I'm having problems getting sFTP working while there are no problems with ssh. I'm basically building zlib, openssl, and openssh for an ARM processor using an existing embedded Linux filesystem. After searching for ideas, this seemed liked a common problem, but I haven't made any progress. I only have one user defined, which is root with a empty password.
I'm using openssh version 4.7p1, and I modified sshd_config with the following settings:
PermitRootLogin yes
PermitEmptyPasswords yes
UseDNS yes
UsePrivilegeSeparation no
SyslogFacility AUTH
LogLevel DEBUG3
Subsystem sftp /usr/local/libexec/sftp-server -f AUTH -l DEBUG3
The sftp-server is located in /usr/local/libexec and has the following permissions:
root@arm:/usr/local/libexec# ls -l
-rwxr-xr-x 1 root root 65533 Oct 3 22:12 sftp-server
-rwx--x--x 1 root root 233539 Oct 3 22:12 ssh-keysign
I know sftp-server is being found (path is set in sshd_config) because if I rename the sftp_server executable, I get the following error:
auth.err sshd[1698]: error: subsystem: cannot stat /usr/local/libexec/sftp-server: No such file or directory
auth.info sshd[1698]: subsystem request for sftp failed, subsystem not found
Also, the target's login init-scripts are very simple and consists of a single file (etc/profile.d/local.sh), which only contain definitions for LD_LIBRARY_PATH, PATH and PYTHONPATH as shown below:
#!/bin/sh
export LD_LIBRARY_PATH="/usr/local/lib"
export PATH="/usr/local/bin:/usr/local/libexec:${PATH}"
export PYTHONPATH="/home/root/python"
As you can see .bashrc, .profile, etc do not exist in root's home directory:
root@arm:~# ls -la
drwxr-xr-x 2 root root 4096 Oct 4 14:57 .
drwxr-xr-x 3 root root 4096 Oct 4 01:11 ..
-rw------- 1 root root 120 Oct 4 01:21 .bash_history
Here is the system log output when using FileZilla to connect to the sftp server on the target. From the log it seems that the sftp-server executable is found, but the child processes is exited immediately. I am using debug arguments when calling sftp-server in sshd_config (Subsystem sftp /usr/local/libexec/sftp-server -f AUTH -l DEBUG3), but no logs were captured.
Oct 4 14:29:45 arm auth.info sshd[2070]: Connection from 192.168.1.12 port 45888
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: Client protocol version 2.0; client software version PuTTY_Local:_Mar_28_2012_12:33:05
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: no match: PuTTY_Local:_Mar_28_2012_12:33:05
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: Enabling compatibility mode for protocol 2.0
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: Local version string SSH-2.0-OpenSSH_4.7
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: fd 3 setting O_NONBLOCK
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: list_hostkey_types: ssh-rsa,ssh-dss
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: SSH2_MSG_KEXINIT sent
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: SSH2_MSG_KEXINIT received
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellma1
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysr
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysr
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: none,[email protected]
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: none,[email protected]
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit:
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit:
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: first_kex_follows 0
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: reserved 0
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellma1
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: aes256-ctr,aes256-cbc,[email protected],aes192-ctr,aes192-cbc,aes128-ctr,aes128-cbc,blowfish-ctr,blowfi8
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: aes256-ctr,aes256-cbc,[email protected],aes192-ctr,aes192-cbc,aes128-ctr,aes128-cbc,blowfish-ctr,blowfi8
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: hmac-sha1,hmac-sha1-96,hmac-md5
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: hmac-sha1,hmac-sha1-96,hmac-md5
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: none,zlib
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: none,zlib
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit:
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit:
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: first_kex_follows 0
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_parse_kexinit: reserved 0
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: mac_setup: found hmac-sha1
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: kex: client->server aes256-ctr hmac-sha1 none
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: mac_setup: found hmac-sha1
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: kex: server->client aes256-ctr hmac-sha1 none
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: SSH2_MSG_KEX_DH_GEX_REQUEST_OLD received
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: dh_gen_key: priv key bits set: 277/512
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: bits set: 2052/4096
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: bits set: 2036/4096
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: kex_derive_keys
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: set_newkeys: mode 1
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug2: cipher_init: set keylen (16 -> 32)
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: SSH2_MSG_NEWKEYS sent
Oct 4 14:29:45 arm auth.debug sshd[2070]: debug1: expecting SSH2_MSG_NEWKEYS
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: set_newkeys: mode 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: cipher_init: set keylen (16 -> 32)
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: SSH2_MSG_NEWKEYS received
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: KEX done
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: userauth-request for user root service ssh-connection method none
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: attempt 0 failures 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug3: Trying to reverse map address 192.168.1.12.
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: parse_server_config: config reprocess config len 302
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: input_userauth_request: setting up authctxt for root
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: input_userauth_request: try method none
Oct 4 14:29:46 arm auth.info sshd[2070]: Accepted none for root from 192.168.1.12 port 45888 ssh2
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: Entering interactive session for SSH2.
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: fd 4 setting O_NONBLOCK
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: fd 5 setting O_NONBLOCK
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: server_init_dispatch_20
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: server_input_channel_open: ctype session rchan 256 win 2147483647 max 16384
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: input_session_request
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: channel 0: new [server-session]
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_new: init
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_new: session 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_open: channel 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_open: session 0: link with channel 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: server_input_channel_open: confirm session
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: server_input_channel_req: channel 0 request [email protected] reply 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_by_channel: session 0 channel 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_input_channel_req: session 0 req [email protected]
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: server_input_channel_req: channel 0 request subsystem reply 1
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_by_channel: session 0 channel 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_input_channel_req: session 0 req subsystem
Oct 4 14:29:46 arm auth.info sshd[2070]: subsystem request for sftp
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: subsystem: exec() /usr/local/libexec/sftp-server -f AUTH -l DEBUG3
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: fd 3 setting TCP_NODELAY
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: fd 7 setting O_NONBLOCK
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug3: fd 7 is O_NONBLOCK
Oct 4 14:29:46 arm auth.debug sshd[2073]: debug1: permanently_set_uid: 0/0
Oct 4 14:29:46 arm auth.debug sshd[2073]: debug3: channel 0: close_fds r -1 w -1 e -1 c -1
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: read<=0 rfd 7 len -1
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: read failed
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: close_read
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: input open -> drain
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: ibuf empty
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: send eof
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: input drain -> closed
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: notify_done: reading
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: Received SIGCHLD.
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_by_pid: pid 2073
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_exit_message: session 0 channel 0 pid 2073
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: request exit-status confirm 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_exit_message: release channel 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: write failed
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: close_write
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: output open -> closed
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: send close
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug3: channel 0: will not send data after close
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: rcvd close
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug3: channel 0: will not send data after close
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: is dead
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: gc: notify user
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_by_channel: session 0 channel 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_close_by_channel: channel 0 child 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: session_close: session 0 pid 0
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: gc: user detached
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: is dead
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug2: channel 0: garbage collecting
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: channel 0: free: server-session, nchannels 1
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug3: channel 0: status: The following connections are open:\r\n #0 server-session (t4 r256 i3/0 o3/0 fd 7/7 cfd -1)\r\n
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug3: channel 0: close_fds r 7 w 7 e -1 c -1
Oct 4 14:29:46 arm auth.info sshd[2070]: Connection closed by 192.168.1.12
Oct 4 14:29:46 arm auth.debug sshd[2070]: debug1: do_cleanup
Oct 4 14:29:46 arm auth.info sshd[2070]: Closing connection to 192.168.1.12
|
While this is more of an alternate solution than a direct answer to your issue, I would try using the internal sftp server instead of an external one. Since this is an embedded system, this probably makes more sense to do anyway.
In your sshd_config, just add:
Subsystem sftp internal-sftp
That way you can leave out the sftp binary and save some space.
| sFTP server fails to start |
1,635,063,773,000 |
Is it possible to query ~/.ssh/config in the command line? Let's say I would like to retrieve what IP address does the particular alias point to in a separate program, is it possible?
|
If I understand that you just want the IP address returned, ie., 192.168.1.1, then this is one (incredibly brittle) way of querying the file from the command line, provided you have the appropriate permissions to read it and your .ssh/config is consistently formatted:
awk '/Host $youralias/ {getline; print $2}' .ssh/config
I am only posting this as I would like to understand how to use awk to do this, but my knowledge is, obviously, quite limited.
| OpenSSH - map aliases in ~/.ssh/config to IP addresses in command line |
1,635,063,773,000 |
I have openssh-server installed on a Debian Jessie host and am trying to find the original version of the sshd_config file. But that was apparently not installed by openssh-server:
root@apu ~$ dpkg -S /etc/ssh/sshd_config
dpkg-query: no path found matching pattern /etc/ssh/sshd_config
What am I missing? Are there config files in Debian that are not managed by dpkg?
|
There are quite a few configuration files which aren't managed by dpkg; they're managed by maintainer scripts instead. In this case, in Debian 9 the original file is available as /usr/share/openssh/sshd_config; that's copied to /etc/ssh/sshd_config by openssh-server.postinst. In Debian 8 the original contents are stored in openssh-server.postinst directly.
| Where is my /etc/ssh/sshd_config coming from? |
1,635,063,773,000 |
ssh clients (by default, at least in Ubuntu 18.04 and FreeBSD 12) always check if server's key fingerprint is in the known_hosts file.
I have a host in the LAN which has dual boot; both the OSs use the same static IP. I would like to connect through ssh to both of them, without encountering errors.
This obviously violates the checks performed on known_hosts: if I accept one fingerprint, it will be related to the host IP; when OS is switched, the fingerprint changes, while the IP is the same, and I need to manually delete it in known_hosts before being able to connect again. I would like that one fingerprint, or the other, is accepted when considering that IP.
Is there a client side solution to overcome this issue?
I am using OpenSSH_7.8p1, OpenSSL 1.1.1a-freebsd 20 Nov 2018 and OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017.
Note: I do not want "no check" over the server's fingerprint. I am just wondering if it is possible to relate two alternative fingerprints (not just one) to server's IP address.
|
Your problem is that host keys are just that, they are a key for the host. There is really only supposed to be one per host. Of course there are several because there are several types of key, but I would avoid relying on key types to give you multiple acceptable keys for a single host.
On the server side
My first suggestion is that you consider carefully if you really want to do this on the client side. You could treat these two OS as the same host and simply copy the host key from one to the other.
If you copy /etc/ssh/ssh_host* from OpenSSH you can use these on other operating systems. Although they might need some reformatting depending on the SSH server you run.
But ...
May I ask why you have ruled out server side solutions?. Wouldn't the easiest way be to try to make both OS use the same host key? – Philip Couling
@PhilipCouling Partly for ease of use: one of the OSs is Windows. Partly to not transfer keys from a host to another, which is a sometimes discouraged practice. But the main reason is: I would like to obtain some degree of flexibility in ssh client configuration, if it is possible. – BowPark
I think that what you are looking for is a way to treat the two OS as different hosts even though they share an IP and port number.
On the client side
Perhaps the most reliable way will be to set host specific configuration for each OS. Edit (or create) ~/.ssh/config to add:
Host windows.dualbootbox
Hostname 192.168.10.20
UserKnownHostsFile ~/.ssh/windows.dualbootbox.known_hosts
Host ubuntu.dualbootbox
Hostname 192.168.10.20
UserKnownHostsFile ~/.ssh/ubuntu.dualbootbox.known_hosts
You don't need to specify Hostname if each Host already resolves to an IP. See man ssh_config for more configuration options.
With the above configuration you can then either:
ssh [email protected]
ssh [email protected]
| ssh, accept two key fingerprints for the same server IP |
1,635,063,773,000 |
The ssh-add command lets you specify the lifetime of an identity being added to ssh-agent. For example, if I type
ssh-add -t 1h
the identify will expire after 1 hour. I can then list the identities currently represented by the agent using ssh-add -l.
Is there a way (other than recording information when I run the ssh-add command) to determine the remaining lifetime of an identity? If not, is there some security-related reason why there shouldn't be a way to get this information?
|
No, there is no interface in ssh-agent communication protocol to provide this information. It is used only when adding the key (constraint array), but this is not returned when you list the keys, as the PROTOCOL.agent page describes (there is only key blob and comment for each key).
Requiring this would probably require to change the protocol, which is a run for a long distance.
| Detecting the remaining lifetime of an ssh-agent identity |
1,635,063,773,000 |
Starting an Interactive shell over SSH is slow to one of my servers. Everything leading up to it including negotiating encryption is fast, but then it hangs for 45 seconds. After that, it finishes and I have a shell. How do I identify what it's hanging on? I tried clearing the environment and disabling all forwarding in case that was slowing it down but it didn't help. Here's my test command:
env -i ssh -x -a -vvv server
and here's the output from SSH:
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Requesting [email protected]
debug1: Entering interactive session.
*(hangs for 45 seconds here)*
debug3: Wrote 128 bytes for a total of 3191
debug2: callback start
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug1: Sending environment.
|
pam_krb5.so was configured to acquire AFS tokens for a non-existent shell which had a 30 second timeout halting any authentication using that module, not just SSH. Removed that and authentication happens much quicker.
| SSH slow at starting session |
1,635,063,773,000 |
I have a host which I ssh into. Sometimes I'm inside the same network, and can ssh directly into it, other times I'm outside it and I need to use a proxy.
Because ssh via the proxy server is much slower than direct, I'd like to have my ssh config set up such that I try to connect directly, falling back to the proxy if that fails.
Currently the config looks like:
Host proxy_server
User user
Port port
Hostname some_domain
Host target_host
User user
Port port
Hostname ip_addr_of_host
Match exec not_inside_network
ProxyCommand ssh -W %h:%p proxy_server
The target_host entry is the last entry in my config file, yet not_inside_network gets called by any ssh connection to unrelated servers in the config file. How can I make Match only apply to this one server?
|
Match is rather on-par with Host. It doesn't exist as a subset of Host the way other options do.
But you can specify multiple criteria on a match, and they appear to operate as a short-circuit AND. So this should be possible and useful for you:
Match host target_host exec not_inside_network
ProxyCommand ssh -W %h:%p proxy_server
This rule will be checked on every ssh. But for hosts not matching "target_host", the match immediately fails and moves to the next Match or Host keyword (if any). Only if the host is "target_host" will the exec occur. Then the truth of that statement will determine whether or not the ProxyCommand is invoked.
To see the logic occur, run with -vvv. You should see some match checks at debug3.
| Only apply Match keyword to single Host in ssh config |
1,635,063,773,000 |
In my automated backups, I'm not sure if I should be doing this. If the hard drive fails or if I wipe the hard disk and start over, what will be the effect of starting with a new SSH host key to my clients? Will I have to do anything special other than remove the host's name from each client's known_hosts file? What is the best thing to do in this case? I'm planning on wiping my computer and starting from scratch in the next few days.
|
If you're reinstalling the OS on your computer, but you consider that it's still the “same” computer, then you must back up the SSH private key and restore it after the installation. If you're reusing the same hardware to make a different system, then you must generate a new key for the new system. Deciding whether it's still the same computer is a semantic decision, so it's up to you; restoring or regenerating the SSH key is the implementation of this decision.
If you're the only person accessing that computer, it doesn't matter much. If you have other users, changing the SSH key will cause trouble:
The few users who are both security-conscious and knowledgeable will worry that something bad is happening and try to contact you out of band to warn you that they may be under attack.
The few users who are knowledgeable but not that paranoid will remove the old SSH key to get rid of the error message, and grumble about the sysadmin changing the key.
The majority of users who ignore messages are just going to see that they can't connect and may contact you for help.
| Should I be backing up my SSH host keys? |
1,635,063,773,000 |
In some tutorials around the web to install OpenSSH exists the following commands:
sudo apt install openssh-server
sudo apt install openssh-client
For example for Ubuntu Desktop is mandatory install the Openssh's Server - and it is not necessary for Ubuntu Server, it is already installed - furthermore I have never installed in some distribution the Openssh's Client, but I am able to connect to some host with ssh.
How to know the version of each one? In ssh(1) - Linux man page indicates:
-V' Display the version number and exit.
But is not clear if is for the server or client - in many tutorials has the same indication about to execute ssh -V, but they do not indicate explicitly if is for the server or client.
Reason:
I want to know the client version, because suddenly my laptop with MacOS can't do ssh for some hosts anymore (it after to did do an upgrade in the hosts Ubuntu from 20.04 to 22.04), while for another laptops with Linux (as client) they can do the ssh to the same hosts yet - after to did do a research, seems it is due the client version - therefore I want to know the client versions from MacOS and Linux.
|
for client:
$ ssh -V
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f 31 Mar 2020
for server:
$ sshd -V
unknown option -- V
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f 31 Mar 2020
or
nc -w1 localhost 22
SSH-2.0-OpenSSH_8.9p1 xxxx
| Commands to know the version of OpenSSH client and server? |
1,635,063,773,000 |
I generated the keypair in Computer 1.
And move the public key to the Computer2(server) and make it in authorized_keys.
And move the private key to Computer3(client) and use ssh-add to add it.
Why I can directly login to server without offering a public key? What's the real workflow of ssh key authorization?
|
The client (Computer 3) does have access to the public key
You are perhaps confusing a private key file with a private key.
When you generate a public/private key pair, most implementations will create a private key file which contains BOTH the private and public key.
Many implementations also write public key to a file separately for convenience.
According RFC 4252 Section 7 the public key is supplied by the client during authentication. Therefore your client MUST have it available.
With openssh's ssh-keygen you can extract the public key from your private key file:
ssh-keygen -y -f ~/.ssh/id_rsa
The authentication mechanism
https://www.rfc-editor.org/rfc/rfc4252#section-7
Before the client tries to login, it may first check to see what would be acceptable. This check can include sending public keys matching its available private keys and thus allows the server to indicate which public/private key to use.
... the signing operation involves some expensive computation. To
avoid unnecessary processing and user interaction, the following
message is provided for querying whether authentication using the
"publickey" method would be acceptable.
byte SSH_MSG_USERAUTH_REQUEST
string user name in ISO-10646 UTF-8 encoding [RFC3629]
string service name in US-ASCII
string "publickey"
boolean FALSE
string public key algorithm name
string public key blob
Then it attempts to login
To perform actual authentication, the client MAY then send a
signature generated using the private key. The client MAY send the
signature directly without first verifying whether the key is
acceptable. The signature is sent using the following packet:
byte SSH_MSG_USERAUTH_REQUEST
string user name
string service name
string "publickey"
boolean TRUE
string public key algorithm name
string public key to be used for authentication
string signature
Notice that this includes both the public key and a signature generated with the private key. The public key is helpful to the server SSH where it has many "authorized keys"; the server doesn't have to test the signature against each one.
Unlike some similar algorithms, SSH doesn't use a challenge-response. That is it doesn't use a four step (1 client initiate, 2 server challenge, 3 client sign, 4 server verifies) it performs a two step:
Client signs the session identifier (Ie: a hash produced by the earlier DH Key Exchange)
The server then verifies that:
The the specified public key is acceptable (in the user's authorized keys)
Decrypting the signature with the specified public key, produces the session identifier
Why are some people confused about this?
The technique of public / private key authentication doesn't need the client to hold the public key. The client just needs to write a signature with the private key. The server just needs to check the signature with the matching public key.
However SSH allows a client to have many private keys and the server to have many authorized keys for a user. If a client had 10 keys and the server accepted 10 keys but only one pair of them matched, the client would have to send 10 signatures and the server would have to check each against 10 keys (100 checks in all). This is computationally expensive. SSH instead can handle the same situation with just a single signature check.
| Why I can use only private key to login a server using ssh? |
1,635,063,773,000 |
Is each a different side of the connection or a deeper layer of logging. I am interested because of, for example, this excerpt from a vvv output
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
Connection reset by nnnn port 22
Looking through the output I can't determine which side is saying what.
|
The short answer:
Yes!
The long answer:
From [man ssh][1]:
-v Verbose mode. Causes ssh to print debugging messages about its
progress. This is helpful in debugging connection, authentication, and configuration problems. Multiple -v options increase
the verbosity. The maximum is 3.
To see what it really does, have a look at the [edits on this question][2] as we asked the OP to go from -v to -vvv (Debug levels 2 and 3 for -vv and -vvv respectively)
For even more information, have a look at RFC4252, Section 6
[1]: http://man7.org/linux/man-pages/man1/ssh.1.html
[2]: https://unix.stackexchange.com/posts/483302/revisions
"SSH forwarded through modem recently started failing"
| What are the various levels in ssh -vvv: debug1, debug2, debug3 |
1,635,063,773,000 |
I am looking for an in-depth explanation of the following ProxyCommand, down to the nuts and bolts of its operation, please. Can you kindly completely dissect it for me and improve on it if you can? For readability, if nothing else.
ProxyCommand ssh gatewayserver 'exec 3<>/dev/tcp/targetserver/22; cat <&3 & cat >&3;kill $!'
|
(I don't have a /dev/tcp device on my system; however bash seems to have some built-in handling for it, allocating a tcp socket connected to the following /host/port part.)
So, your ssh proxy command securely runs a shell on gatewayserver which does:
exec 3<>/dev/tcp/targetserver/22
i.e. attach a socket on filedescriptor 3 (connected to the targetserver/port). Then:
cat <&3 & cat >&3; kill $!
which is a way to have a bidirectional redirection (using two separate processes) between the couple of filedescriptors 0(input) and 1(output), and filedescriptor 3(input and output). The kill $! is there to kill the background process cat <&3 after the other process cat >&3 has returned.
All this is just some equivalent of a more standard:
ProxyCommand ssh gatewayserver "tcpconnect targetserver port"
using /dev/tcp (or bash) features instead of the tcpconnect command.
Some more details:
The proxy command used by ssh is there to define how to connect to the remote host targetserver (encryption is not really needed there because ssh protocol will be used over this channel). In our case, we want to establish the connection to this target host trough gatewayserver (probably because a firewall prevents to connect to targetserver directly.
So a process
ssh gatewayserver 'exec 3<>/dev/tcp/targetserver/22; cat <&3 & cat >&3;kill $!'
is started and:
filedescriptor(fd) 1 (a.k.a. standard output) will be used by an ssh client to send data to the target host.
fd 0 (a.k.a. standard input) will be used by an ssh client to read data from the remote host.
The ssh gatewayserver is used to first connect to the gateway which will be the first hop. A new shell is started on this host, and this ssh instance will relay fd 0/fd 1 of the process on the origin host to fd 0/fd 1 of the shell running on gateway host. The command executed by this shell is:
exec 3<>/dev/tcp/targetserver/22; cat <&3 & cat >&3;kill $!
The exec without a command won't execute anything, it will just apply the following redirections the shell itself. Usual redirections are:
n>file to redirect fd n to file (open for writting only, n is 1 if ommited).
n<file to redirect fd n to file (open for reading only, n is 0 if ommited).
n<>file to redirect fd n to file (open for reading and writting).
when specified as n>&m or n<&m or n<>&m, the fd n is redirected to the file previously pointed to by fd m.
Here the following is used:
exec 3<>/dev/tcp/targetserver/22
This will redirect a newly created fd 3 to some very special file /dev/tcp/targetserver/22 (which is not really a file, but something bash understands natively). Here, bash creates a socket (special file which uses the tcp protocol) to talk to targetserver on port 22 (Where we expect to find a sshd server), and this file is open (read&write) on fd 3.
Now we need to "pump" data on fd 0 (data from client) and send it to fd 3 (connected to the target server).
We also need to assure backward communication by "pumping" data on fd 3 and sending it back to fd 1 (result for client).
Those two "pumps" are set up using two cat processes:
cat <&3 (which reads from the shell's fd 3 and write to the shell's fd 1.)
cat >&3 (which reads from the shell's fd 0 and write to the shell's fd 3.)
Both cats must be run in parallel, so one needs to be backgrounded. Here, we want the one that reads on fd 0 (which will probably be a tty) be the one left in the foreground. This gives:
cat <&3 & #run in the background
cat >&3; kill $!
The kill $! is there to kill the background process ($! expands to the pid of the last backgrounded process). This way when the client hangs up, the foreground process terminates, the kill is performed, and the last process is terminated too.
That's it! We've made the bridge:
origin host —(ssh)→ gateway —(pumps+socket)→ targetserver(port 22)
An ssh user@targetserver on the origin host will be able to connect to the target host through this bridge!
| All about ssh ProxyCommand |
1,635,063,773,000 |
On my server, I have several public SSH keys in ~/.ssh/authorized_keys.
I would like to temporarily block/disallow/deactivate one key. I want to prevent the user to log in using this key now. but I might want to reanable it later (i.e. I don't want to delete the key entirely).
What is the correct/recommended way to do it?
Shall I just put a comment # at the beginning of the line in authorized_keys, in front of the key?
To clarify, I don't want to block a specific user. One user account is shared among several people, each person connecting with his own SSH key. I want to block one specific SSH key.
|
You could prefix the key with a forced command that tells the user what's going on. For example:
restrict,command="printf 'Your key has been disabled\n'" ssh-rsa AAAAB2...19Q== [email protected]
or for Openssh before v7.2:
command="printf 'Your key has been disabled\n'",no-pty,no-port-forwarding ssh-rsa AAAAB2...19Q== [email protected]
Then they get:
$ ssh servername
PTY allocation request failed on channel 0
Your key has been disabled
Connection to servername closed.
| temporarily disable login using one specific ssh key |
1,635,063,773,000 |
I have my SSH client configured to multiplex my sessions:
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600
I'm occasionally bumping into the default OpenSSH server side MaxSessions limit of 10. The obvious answer is to increase MaxSessions to a number significantly larger than I'd ever need.
Is there a reason to not just set it to 1000000? The default of 10 suggests this is some reason not to.
All I can come up with is perhaps past 10 or so, busy connections might be less efficient, but seeing as the harm would be limited to myself, I'm not sure this is the reason.
|
There is always a reason why to limit anything. The 10 is "sane default". The less is for more restrictive use cases (preventing shell access or allowing only single channel), bumping it to more can also make a sense, if you really know, you will be issuing millions of sessions. I rarely open more than 4.
To the question:
Is there a reason to not just set it to 1000000?
max_sessions variable has int type, so the maximum possible value is 2147483647. Nothing prevents you setting up your ideal million.
... but as already mentioned, there is no good reason to do that.
There is no significant security effect in using more sessions (once single session of attacker is opened, you are screwed), but there might be performance penalty when using more of them.
| Why not set OpenSSH's MaxSessions to 1000000? [closed] |
1,635,063,773,000 |
I have the following setup where I use an OpenSSH server to remotely start a certain command using ssh.
My authorized_keys file has the following entry:
command="/path/to/script.sh $SSH_ORIGINAL_COMMAND",no-port-forwarding,no-x11-forwarding,no-agent-forwarding ssh-rsa AAAA…qGDf my_special_key
This means that if anyone connects using that key (e.g. by using ssh -i special_key_file user@server) the script script.sh gets executed on my server. Now there is also the $SSH_ORIGINAL_COMMAND placeholder which gets replaced by all the extra command line to the ssh command, i.e. ssh -i special_key_file user@server foobar means that the $1 will have foobar in it.
To test it I can make my script.sh look the following:
#!/bin/sh
printf '<%s>\n' "$@"
Now for ssh -i special_key_file user@server 'foo bar' just like for ssh -i special_key_file user@server foo bar I will get the following same result:
<foo>
<bar>
Because of splitting. And if that wasn't bad enough, for ssh -i special_key_file user@server '*' I'm getting a file list:
<file1>
<file2>
…
So apparently the whole extra command line gets inserted into what is inside command= which is then run in a shell, with all the splitting and globing steps happening. And apparently I can't use " inside the command="…" part so I can't put $SSH_ORIGINAL_COMMAND inside double quotes to prevent that from happening. Is there any other solution for me?
BTW, as explained in this dismissed RFE to introduce a $SSH_ESCAPED_ORIGINAL_COMMAND the ssh protocol is party to blame as all the extra command line is transferred as one string. Still this is no reason to have a shell on the server side do all the splitting, especially if it then also does the glob expansion (I doubt that is ever useful here). Unlike the person who introduced that RFE I don't care about splitting for my use case, I just want no glob expansion.
Could a possible solution have to do with changing the shell environment OpenSSH uses for this task?
|
Use quotes:
cat bin/script.sh
#!/bin/sh
printf '<%s>\n' "$@"
command="/home/user/bin/script.sh \"${SSH_ORIGINAL_COMMAND}\"" ssh-rsa AA...
ssh -i .ssh/id_rsa.special hamilton '*'
<*>
ssh -i .ssh/id_rsa.special hamilton 'foo bar'
<foo bar>
But also you will get:
ssh -i .ssh/id_rsa.special hamilton '*' 'foo bar'
<* foo bar>
Not sure is it a problem for you or not.
And I was confused about:
And apparently I can't use " inside the command="…"
I thought it's kind of limitation in your task so deleted my answer.
I'm glad my answer helped you with your task!
| OpenSSH: Prevent globbing on SSH_ORIGINAL_COMMAND |
1,635,063,773,000 |
By default, my SSH client disallows the use of the diffie-hellman-group-exchange-sha256 key exchange algorithm. However, I need to access a server on 10.0.0.1 that requires the use of that algorithm.
This works fine at the command line:
$ ssh -o KexAlgorithms=diffie-hellman-group-exchange-sha256 [email protected]
Password:
However, it fails if I attempt to rely on the following addition at the end of /etc/ssh/ssh_config:
Host 10.0.0.1
KexAlgorithms diffie-hellman-group-exchange-sha256
Here is the relevant output:
$ ssh -vvv [email protected]
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug3: kex names ok: [[email protected]]
...
debug1: /etc/ssh/ssh_config line 72: Applying options for 10.0.0.1
debug3: kex names ok: [diffie-hellman-group-exchange-sha256]
...
debug1: Connecting to 10.0.0.1 [10.0.0.1] port 22.
debug1: Connection established.
...
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: [email protected]
...
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256
...
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: setup hmac-ripemd160
debug1: kex: server->client aes256-ctr hmac-ripemd160 none
debug2: mac_setup: setup hmac-ripemd160
debug1: kex: client->server aes256-ctr hmac-ripemd160 none
Unable to negotiate a key exchange method
What I find puzzling about this is that SSH is clearly reading the relevant line in /etc/ssh/ssh_config and seems to be happy with it. But then it tries to negotiate a key exchange with the server using [email protected] instead of diffie-hellman-group-exchange-sha256, which of course fails.
Why does it do that, and how can I rectify it?
|
OpenSSH options might behave somehow strange on the first sight. But manual page for ssh_config documents it well:
For each parameter, the first obtained value will be used. The configuration files contain sections separated by “Host” specifications, and that section is only applied for hosts that match one of the patterns given in the specification. The matched host name is usually the one given on the command line (see the CanonicalizeHostname option for exceptions.)
You might rewrite your config like this to achieve what you need (the star * match should be last):
Host 10.0.0.1
KexAlgorithms diffie-hellman-group-exchange-sha256
#[...]
Host *
KexAlgorithms [email protected]
From my duplicate answer
And to explain why the commandline option works, also from the same manual page for ssh_config:
command-line options
user's configuration file (~/.ssh/config)
system-wide configuration file (/etc/ssh/ssh_config)
| Specifying SSH KexAlgorithms works at CLI but not via ssh_config [duplicate] |
1,635,063,773,000 |
The title basically says it all. But mind: host key, not the login key.
And if they're not compatible out of the box, is there a way to convert between them - and what would be the steps in that case?
Rationale: it would be nice to be able to bring up a dropbear instance in the scope of the initrd, if boot fails, but do so by incorporating the host keys (via initramfs-tools hooks) from OpenSSH that is normally installed on the host.
|
After the misunderstanding that I am referring to host keys instead of login keys, I decided to dig into this a little myself. The main point was to establish whether the formats are compatible, not whether they're different (I knew they are).
Trying to install dropbear over a system that already had OpenSSH of course failed miserably, but this wasn't the point of the exercise. During the installation (and before the failure) the output said:
Converting existing OpenSSH RSA host key to Dropbear format.
So a quick apt-get source dropbear and grep-ing inside the debian subfolder yielded:
dropbear.postinst: echo "Converting existing OpenSSH RSA host key to Dropbear format."
Promising. The relevant lines in the dropbear.postinst script read:
echo "Converting existing OpenSSH RSA host key to Dropbear format."
/usr/lib/dropbear/dropbearconvert openssh dropbear \
/etc/ssh/ssh_host_rsa_key /etc/dropbear/dropbear_rsa_host_key
Apparently dropbear comes with a tool named dropbearconvert, which has a .c source file in the source and comes with a man page: dropbearconvert(1). Because I was unable to come up with an online version of the man page, here the gist:
SYNOPSIS
dropbearconvert input_type output_type input_file output_file
[...]
OPTIONS
input type
Either dropbear or openssh
output type
Either dropbear or openssh
input file
An existing Dropbear or OpenSSH private key file
output file
The path to write the converted private key file
| Are dropbear and OpenSSH host keys compatible? |
1,454,834,906,000 |
I want a host section in my ssh config that matches any local IP:
Host 10.* 192.168.*.* 172.31.* 172.30.* 172.2?.* 172.1?.*
setting
setting
...
This works as long as I connect directly to a relevant IP. If I however connect to a hostname that later resolves to one of these IPs, the section is ignored.
sshd has Match Address sections which I think can be used for this, but they won't work in ssh client configs.
Is there any way to achieve this?
|
You can't do that using only ssh_config options, but there is exec option, which can do that for you:
Match exec "getent hosts %h | grep -qE '^(192\.168|10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.)'"
setting
| ssh_config: Add a host section that matches IPs even when connecting via hostname |
1,454,834,906,000 |
Since I want to protect my ssh connections, I set some global cipher suite options to restrict set of used algorithms. But recently I've encountered a server which doesn't support some of those algorithms. So, I need to selectively enable deprecated algorithms for a specific host record in client (my system) configuration.
I found out that the options override is not working as I expected. Let's take a minimal (not-)working example for the github:
HostKeyAlgorithms [email protected],ssh-ed25519,[email protected],ecdsa-sha2-nistp521,ecdsa-sha2-nistp256
Host github
HostKeyAlgorithms ssh-rsa
Hostname github.com
Port 22
User git
PubkeyAuthentication yes
IdentityFile ~/.ssh/some-filename-here
Having that, I receive the following error (HostKeyAlgorithms is not overriden at all):
debug1: /home/username/.ssh/config line 14: Applying options for github
<...>
debug2: kex_parse_kexinit: [email protected],ssh-ed25519,[email protected],ecdsa-sha2-nistp521,ecdsa-sha2-nistp256
<...>
Unable to negotiate with 192.30.252.130: no matching host key type found. Their offer: ssh-dss,ssh-rsa
It is similarly not working for the global PubkeyAuthentication no options with an override in a host configuration.
Also, the match doesn't help either:
match host github
HostKeyAlgorithms ssh-rsa
So, is there a way to selectively redefine those options?
NOTE: I'm using the openssh-7.1_p2-r1 on gentoo.
|
OpenSSH options might behave somehow strange on the first sight. But manual page for ssh_config documents it well:
For each parameter, the first obtained value will be used. The configuration files contain sections separated by “Host” specifications, and that section is only applied for hosts that match one of the patterns given in the specification. The matched host name is usually the one given on the command line (see the CanonicalizeHostname option for exceptions.)
You might rewrite your config like this to achieve what you need:
Host github
HostKeyAlgorithms ssh-rsa
Hostname github.com
Port 22
User git
PubkeyAuthentication yes
IdentityFile ~/.ssh/some-filename-here
Host *
HostKeyAlgorithms [email protected],ssh-ed25519,[email protected],ecdsa-sha2-nistp521,ecdsa-sha2-nistp256
| options override for openssh client configuration |
1,454,834,906,000 |
How to disable ChaCha20-Poly1305 encryption from ssh under Debian?
I tried (as root):
echo 'Ciphers [email protected]' > /etc/ssh/sshd_config.d/anti-terrapin-attack
echo 'Ciphers [email protected]' > /etc/ssh/ssh_config.d/anti-terrapin-attack
systemctl restart sshd
But my ssh -Q cipher is still showing [email protected].
UPDATE:
As the answers to fully solving my question are spreading across different answers, let me summarize them in one place.
Why? what's the fuss? -- check out Attack Discovered Against SSH, and Debian's openssh stable version is generations behind the official fix. Thus I need to fix it myself now.
Why OP is not working? -- two points:
ssh -Q cipher always shows all of the ciphers compiled into the binary
all configuration files in the "/etc/ssh/sshd_config.d" directory should end with ".conf".
How to disable the attack? -- See Floresta's practical solution https://unix.stackexchange.com/a/767135/374303
How to verify that the attack is disabled? -- based on gogoud's practical solution:
nmap --script ssh2-enum-algos -sV -p 22 localhost | grep chacha20 | wc
0 0 0
Better run it before and after applying Floresta's fixes.
|
ssh -Q cipher always shows all of the ciphers compiled into the binary, regardless of whether they are enabled or not. This is true also for algorithms which are insecure or disabled by default.
The configuration you have set up should be sufficient to disable the algorithm, assuming you're using a recent version of OpenSSH which supports this syntax. You can verify this by attempting to connect via ssh -vvv, which will print the server to client cipher list.
If you don't have a recent version of OpenSSH, then this syntax is not supported, and you need to explicitly list the ciphers you want. The default is listed in man sshd_config, and, for my version of OpenSSH (Debian's 9.6), would look like this (without ChaCha):
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
Assuming you have modern clients, placing AES-GCM first in the list will improve performance (and security if you're not using encrypt-then-MAC), but there was an older version of OpenSSH which would segfault during rekeying with AES-GCM (which all major distros patched), which is why they're at the end of the list.
Note that if you're using a patched OS on both the client and server, then it's not necessary to disable [email protected]. The reason is that authorized clients and servers will negotiate a secure connection with the [email protected] and [email protected] extensions that are in patched versions of OpenSSH. It doesn't matter what random scrapers do, because they'll drop off shortly thereafter and there's no need to protect them.
However, if you aren't using a patched OS, then of course you're vulnerable, but then again, you're vulnerable to a variety of other vulnerabilities as well.
| How to disable ChaCha20-Poly1305 encryption to stop the terrapin ssh attack |
1,454,834,906,000 |
Here's the problem: I'm trying to SSH into a system that is accessible from at least 3 different networks—sometimes directly, sometimes via a proxy—at different times.
Connecting directly is far faster and more reliable than connecting via an intermediate host, which is again far faster and more reliable than connecting over the general internet, so I would like SSH to attempt to connect in 3 different ways in a prioritized fashion, picking the first that succeeds.
They're all the same machine, obviously, so I don't want to keep having to manually choose between 3 different aliases depending on where I'm connecting from.
However, I can't find any mechanism for solving this. Is it possible to do this at all, or no?
If not, what do people generally do in such a situation?
|
Do not use aliases for ssh connections! Use a proper ssh_config in ~/.ssh/config. It has some truly powerful features.
Lets say you can identify in which network you are. For example using your IP, which can be pulled for example using hostname -I. So lets write some configuration:
# in network1 I am getting ip from "10.168.*.*" and I need to connect through proxy
Match Host myalias Exec "hostname -I | grep 10\.168\."
Hostname real-host-IP
ProxyCommand ssh -W %h:%p proxy-server
# in network2 I am getting IP from "192.168.*.*" and I do not need a proxy
Match Host myalias Exec "hostname -I | grep 192\.168\."
Hostname real-host-IP
# in network3 I am getting something else
| How to use the same SSH alias with multiple host addresses/ports/etc.? |
1,454,834,906,000 |
Possible Duplicate:
How to speed my too-slow ssh login?
I have a very strange issue with my SSH server. Whenever I attempt to connect, it literally waits about 30 seconds to a minute before allowing the connection. Other servers in the same datacenter are connecting in about 2-3 seconds, while this one waits just about the same amount of time before letting any connections through. Is there a configuration option which I can use to tweak this delay time? It's running OpenSSH 4.3p2, OpenSSL 0.9.8e-fips-rhel5.
Here's the output from ssh -v user@myserver:
OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to myserver [2.2.2.2] port 22.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/rfkrocktk/.ssh/id_rsa" as a RSA1 public key
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'Proc-Type:'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'DEK-Info:'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /home/rfkrocktk/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/rfkrocktk/.ssh/id_rsa-cert type -1
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/rfkrocktk/.ssh/id_dsa" as a RSA1 public key
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'Proc-Type:'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'DEK-Info:'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /home/rfkrocktk/.ssh/id_dsa type 2
debug1: Checking blacklist file /usr/share/ssh/blacklist.DSA-1024
debug1: Checking blacklist file /etc/ssh/blacklist.DSA-1024
debug1: identity file /home/rfkrocktk/.ssh/id_dsa-cert type -1
debug1: identity file /home/rfkrocktk/.ssh/id_ecdsa type -1
debug1: identity file /home/rfkrocktk/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.8p1 Debian-1ubuntu3
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "myserver" from file "/home/rfkrocktk/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/rfkrocktk/.ssh/known_hosts:27
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],ssh-rsa
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: [email protected],[email protected],ssh-rsa,[email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 124/256
debug2: bits set: 515/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA cd:e9:ff:ef:af:d0:a9:f4:23:85:4b:32:6c:be:f3:bc
debug3: load_hostkeys: loading entries for host "myserver" from file "/home/rfkrocktk/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/rfkrocktk/.ssh/known_hosts:27
debug3: load_hostkeys: loaded 1 keys
debug3: load_hostkeys: loading entries for host "2.2.2.2" from file "/home/rfkrocktk/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/rfkrocktk/.ssh/known_hosts:34
debug3: load_hostkeys: loaded 1 keys
debug1: Host 'myserver' is known and matches the RSA host key.
debug1: Found key in /home/rfkrocktk/.ssh/known_hosts:27
debug2: bits set: 534/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/rfkrocktk/.ssh/id_dsa (0x7f3a27677d40)
debug2: key: /home/rfkrocktk/.ssh/id_rsa (0x7f3a27677d00)
debug2: key: /home/rfkrocktk/.ssh/id_ecdsa ((nil))
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-with-mic,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
Credentials cache file '/tmp/krb5cc_1000' not found
debug1: Unspecified GSS failure. Minor code may provide more information
Credentials cache file '/tmp/krb5cc_1000' not found
debug1: Unspecified GSS failure. Minor code may provide more information
debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering DSA public key: /home/rfkrocktk/.ssh/id_dsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Offering RSA public key: /home/rfkrocktk/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug2: input_userauth_pk_ok: fp 1a:10:d2:9b:88:35:6d:be:c0:b2:9b:b0:87:99:0f:d5
debug3: sign_and_send_pubkey: RSA 1a:10:d2:9b:88:35:6d:be:c0:b2:9b:b0:87:99:0f:d5
debug1: Authentication succeeded (publickey).
Authenticated to myserver ([2.2.2.2]:22).
debug2: fd 5 setting O_NONBLOCK
debug2: fd 6 setting O_NONBLOCK
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Entering interactive session.
debug2: callback start
debug2: client_session2_setup: id 0
debug2: fd 3 setting TCP_NODELAY
debug3: packet_set_tos: set IP_TOS 0x10
debug2: channel 0: request pty-req confirm 1
debug1: Sending environment.
debug3: Ignored env ORBIT_SOCKETDIR
debug3: Ignored env SSH_AGENT_PID
debug3: Ignored env TERM
debug3: Ignored env SHELL
debug3: Ignored env XDG_SESSION_COOKIE
debug3: Ignored env WINDOWID
debug3: Ignored env GNOME_KEYRING_CONTROL
debug3: Ignored env GTK_MODULES
debug3: Ignored env USER
debug3: Ignored env SSH_AUTH_SOCK
debug3: Ignored env USERNAME
debug3: Ignored env SESSION_MANAGER
debug3: Ignored env DEFAULTS_PATH
debug3: Ignored env TMUX
debug3: Ignored env XDG_CONFIG_DIRS
debug3: Ignored env PATH
debug3: Ignored env DESKTOP_SESSION
debug3: Ignored env PWD
debug3: Ignored env GDM_KEYBOARD_LAYOUT
debug1: Sending env LANG = en_US.UTF-8
debug2: channel 0: request env confirm 0
debug3: Ignored env MANDATORY_PATH
debug3: Ignored env GDM_LANG
debug3: Ignored env UBUNTU_MENUPROXY
debug3: Ignored env COMPIZ_CONFIG_PROFILE
debug3: Ignored env GDMSESSION
debug3: Ignored env SHLVL
debug3: Ignored env HOME
debug3: Ignored env LANGUAGE
debug3: Ignored env GNOME_DESKTOP_SESSION_ID
debug3: Ignored env LOGNAME
debug3: Ignored env XDG_DATA_DIRS
debug3: Ignored env DBUS_SESSION_BUS_ADDRESS
debug3: Ignored env WINDOWPATH
debug3: Ignored env DISPLAY
debug3: Ignored env IBUS_NO_SNOOPER_APPS
debug3: Ignored env XAUTHORITY
debug3: Ignored env COLORTERM
debug3: Ignored env _
debug2: channel 0: request shell confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug2: channel 0: rcvd close
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug3: channel 0: will not send data after close
debug3: channel 0: will not send data after close
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)
debug1: fd 1 clearing O_NONBLOCK
debug1: fd 2 clearing O_NONBLOCK
Connection to myserver closed.
Transferred: sent 3504, received 2584 bytes, in 26.6 seconds
Bytes per second: sent 131.8, received 97.2
debug1: Exit status 1
It appears it's using weird authentication methods that I don't use.
|
Check the debugging output (-vvv) to see if it is waiting for protocols that don't exist on that server. I've had similar symptoms with gssapi authentication. See where the program is hanging and try to turn off that authentication, for example adding -o GSSAPIAuthentication=no to the command line or to the config file.
| SSH "sleeping" for a long time before connect? [duplicate] |
1,454,834,906,000 |
These do not do the same:
$ seq 1000000 | (ssh localhost sleep 1; wc -l)
675173
$ seq 1000000 | (ssh localhost sleep 1 </dev/null; wc -l)
1000000
What is the rationale for ssh reading stdin?
|
ssh always reads stdin unless you tell it not to with the -n option (or the -f option).
The reason is so that you can do things like
tar cf - somedir | ssh otherhost "tar xf -"
And it always does this because ssh has no way of knowing if your remote command accepts input or not.
Likely what is happening in your first command is that seq fills up the network and pipe buffers (seq -> ssh -> sleep), and since sleep isn't reading anything, it gets blocked waiting for more reads, and then sleep exits, causing those full buffers to be dumped, and then seq is unblocked, feeding the remainder to wc.
Note that you would get similar results with seq 1000000 | ( cat | cat | sleep 1; wc -l)
In your second command, it is still reading stdin, but you've externally assigned /dev/null to stdin.
| ssh reads stdin without being asked to |
1,454,834,906,000 |
Is DNS resolution tunneled to the other end when I use a SOCKS proxy created with ssh -D? I have read the manual, searched the Internet, and found no documentation relevant.
|
DNS resolution via Socks is up to the client. You have to explicitly tell the application to lookup DNS via Socks.
Name resolution is, just like connecting to a host, done by system calls like gethostbyname() or getaddrinfo().
Unless instructed otherwise, a program may just use this function for name resolution which, of course, does not know about your tunnel.
For example curl does only lookup DNS when specifying socks5h://, not only socks5://.
| Does `ssh -D` proxy DNS request? |
1,454,834,906,000 |
I am a beginner and new to development boards and Linux as a whole, and have been using the wonderful SSH package with Debian (I believe this is OpenSSH) to tinker around and learn more without the need to be physically connected to my Pi through a serial cable.
I have followed various websites and threads on this forum to harden and tweak my SSH to be more secure. An important change I'd like to make to my sshd_config file has vexed me however - ListenAddress. As I understand it, the ListenAddress value in sshd_config defines the strict parameter of IP address(es) the server should listen to requests from.
The default value for ListenAddress in sshd_config is 0.0.0.0, which is commented out. I understand that working on a "commented out defaults" policy, the application will default to this value. I've read the Man[ual] Page which indicates the default is to
listen on all local addresses on the current routing domain
and while I can't profess to know a lot about networking, I've read elsewhere 0.0.0.0 indicates the server will listen for requests from any IPv4 address from the internet at large? I am worried this may make my (internet facing) Pi a target for attack, and it seems prudent to limit ListenAddress to only listen for requests from my internal network. I won't have need for access anywhere other than home.
My router (Apple Airport) DHCP Range is 10.0.1.2 to 10.0.1.200, with the router at 10.0.1.1. (This seems to be the default, if I had known more perhaps I should have changed this to 192.168.1.1).
I have tried setting the following ListenAddress values, all of which have locked me out of SSH, necessitating connecting with a USB serial cable to revert ListenAddress back to default:
10.0.1.0 - I thought setting the last octet at 0 may indicate all IPs on the 10.0.1. range
10.0.1.* - I thought using * as a wildcard may work as per the first example as above
10.0.1.** - In case the single * wildcard only indicated a .1 to .9 range
10.0.1.1 - It seems silly now but I thought setting the router's IP may do the trick, as this is the magic 'box' handing out the IP addresses
10.0.1.1/24 - Using /24 to define the first three octets, leaving the last octet as the open 'range'. But it seems sshd_config doesn't recognise the / character
127.0.0.1 - I learned about the localhost or loop back address option, but this didn't work either
10.0.1.24 - My computer's IP. This last throw of the dice didn't work, and on running systemctl status ssh.service returned error: Bind to port 22 on 10.0.1.24 failed: Cannot assign requested address, fatal: Cannot bind any address and Failed to start OpenBSD Secure Shell server messages.
I hope this goes some way to explaining my thinking, and what I've tried so far - I feel I've exhausted all logical options and perhaps 0.0.0.0 is the only permitted option for what I am trying to achieve. Do let me know if my question is better suited to the networking forum instead.
Worryingly, systemctl status ssh.service also advised Deprecated option for the following sshd_config values:
Deprecated option KeyRegenerationInterval
Deprecated option RhostsRSAAuthentication
Deprecated option RSAAuthentication
Deprecated option KeyRegenerationInterval
Deprecated option RhostsRSAAuthentication
Deprecated option RSAAuthentication
However I'm at a loss as to what the program's favoured values for these should be.
I am pushing the limits of my (very limited) knowledge thus far, but I understand from my previous query to this board plenitude and prolixity is encouraged to assist your kind replies.
My sshd_config defaults are v1.103 and the changes I have made are:
AddressFamily inet
AllowUsers keith
Protocol 2
LoginGraceTime 30
KeyRegenerationInterval 3600
PermitRootLogin no
StrictModes yes
MaxAuthTries 3
MaxSessions 1
PubkeyAuthentication yes
IgnoreUserKnownHosts yes
IgnoreRhosts yes
RhostsRSAAuthentication no
RSAAuthentication yes
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
AuthenticationMethods publickey keyboard-interactive
UsePAM yes
X11Forwarding no
PrintMotd no
TCPKeepAlive no
ClientAliveInterval 360
ClientAliveCountMax 0
I have been using a variety of websites and sources for guidance, so some of these values may now be superannuated. I understand SSH security is constantly evolving and something of a moveable feast.
I hope this explains my thought process and methodology, and my apologies for the lack of brevity. Thank you all for your kind help thus far, it is very much appreciated. Never stop learning!
|
The ListenAddress is actually telling which system interface the SSH server should listen on (0:0:0:0 makes it listen to all interfaces). For instance if your system has a Wifi (on 10.0.1.4) and an Ethernet (10.0.1.12), ListenAddress 10.0.1.12 will make it listen only on the Ethernet interface, and other computers will have to SSH to 10.0.1.12 to get a connection.
To restrict external users to a given range of addresses, you can use a firewall, either iptables directly (but it isn't fit for mere humans) or a more palatable front-end such as ufw.
However, since you are behind a router, the router may already block external accesses, systems on the other side of the router do not see your 10.0.1.* adress, for them everything comes from a single address: your router, and to initiate connections from outside to one of your local machines the router would have to be set to perform port-forwarding (connections to some specified port on the router are forwarded to a specific local address:port on your local network).
| How can I restrict SSH to only listen for requests from my local network? |
1,454,834,906,000 |
TLDR
In sshd_config(5), this config segment:
Match Address fe80::/10
PasswordAuthentication yes
... is not matching link-local IPv6 addresses as expected. Why and how to fix?
I am trying to configure sshd to only allow password authentication when connecting from local addresses. Otherwise public key authentication is required. This is the relevant config in sshd_config.
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
# Allow password auth on local network
Match Address 169.254.0.0/16,192.168.0.0/16
PasswordAuthentication yes
Match Address fe80::/10
PasswordAuthentication yes
What works:
Public key authentication enabled on all addresses, as expected.
Password authentication enabled on address range 169.254.0.0/16,192.168.0.0/16 when connecting via IPv4, as expected.
What does not work:
Password authentication is not enabled on address range fe80::/10 when connecting via IPv6.
Relevant line in var/log/secure:
sshd[9457]: Connection reset by fe80::39c9:9db5:5a2a:1299%eth0 port 60468 [preauth]
... which is an address that should be matched by fe80::/10
Checklist items I've done:
IPv6 traffic is not blocked by firewall
sshd is listening on both stacks
$ netstat -tupln | grep sshd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 8903/sshd
tcp6 0 0 :::22 :::* LISTEN 8903/sshd
Combining / splitting the Match statements for IPv4 and IPv6 does nothing
Match Address 169.254.0.0/16,192.168.0.0/16,fe80::/10
This doesn't work either.
Putting the IPv6 address in square brackets
Match Address [fe80::]/10
No bueno.
sshd does not log any config error in var/log/secure
Not a client problem - tried OpenSSH, PuTTY, WinSCP and got the same error
Versions:
sshd running on CentOS 7
$ uname -msr
Linux 5.4.72-v8.1.el7 aarch64
$ ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
I've already asked this question over on /r/sysadmin's discord server, and people's reaction was "weird". See our full conversation here if you are interested. It has some more minor details on the different things I tried.
|
After trying just about everything I could think of, I was able to find a solution that worked for me. I wanted to allow password auth to users on my LAN but only allow key based auth from outside the LAN which is why I ended up finding this post.
From other reading I saw some indication that square brackets should be used with an ipv6 address and I also saw in the sshd logs that it logged the interface name (i.e. eth0, wlan0) where my connection came from when I would connect using ipv6.
I decided to test all of the combos until I found something that worked. I put in my full ipv6 address and did not use a /10 to make sure that the format of that would not interfere and I tried with and without the interface name and with and without brackets (and putting them around different parts of the address) and I can definitively say that sshd does not like the brackets. Any time I included them it did not work.
It also did not work without the interface name specified even if I used my full exact ipv6 address so it seems like sshd expects an ipv6 address to not include square brackets as it would in a URL and expects that it will include the interface name no matter what.
The last piece was the /10 to include all link local addresses. I initially expected the correct form to be fe80::/10%eth0 but surprisingly that did not work. Instead sshd expects you to write fe80::%eth0/10. I guess this kind of makes sense if you view the /10 as modifying the entire ip address where a proper and complete ipv6 address is some number and an interface name while an ipv4 is only the number, but in either case, with that twist unraveled, I had a solution.
This was the full match block I used to allow ipv4 and ipv6 local connections to authenticate with passwords:
Match Address 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,fe80::%eth0/10
PasswordAuthentication yes
Obviously you would need to modify the name eth0 to be the correct interface name for you machine, (you can look at the list of them with ifconfig or check the sshd logs when you attempt to connect via ipv6 to see what interface your connection is using) and If you wanted to support connections from multiple interfaces I think you need to specify ,fe80::%name/10 for each one.
I hope this answer helps others who stumble upon this thread (and maybe OP, though I am not sure how much help this will be five months later)
| sshd_config - "Match Address <IPv6>" not matching |
1,454,834,906,000 |
I have a CentOS VM to which I log in using SSH. I appended the following line to .bashrc
echo "from ~/.bashrc: (pid $$)"
and the following line to .bash_profile
echo "from ~/.bash_profile"
When I log into the VM and run ps I get the following output
user@laptop:~ $ ssh vmcentos
Last login: Sun May 17 04:48:24 2020 from 192.168.122.1
from ~/.bashrc: (pid 1821)
from ~/.bash_profile
[admin@localhost ~]$ ps -H -o pid,command
PID COMMAND
1821 -bash
1844 ps -H -o pid,command
[admin@localhost ~]$
This output is what I expect since the shell I log into is an interactive login shell and thus the .bash_profile file is sourced which in turn sources the .bashrc file.
Now I log out from the VM and execute the following command
user@laptop:~ $ ssh vmcentos 'sleep 60; echo $-'
from ~/.bashrc: (pid 1901)
hBc
user@laptop:~ $
then I log into another ssh session on the VM and inspect the process table
[admin@localhost ~]$ ps -eH -o pid,command
PID COMMAND
(... more output here...)
1900 sshd: admin@notty
1901 bash -c sleep 60; echo $-
1914 sleep 60
(... more output here...)
As far as I understand the shell that ssh executes (process 1901) is non-interactive (because of the -c option and also because the $- variable contains no i character) and non-login (because ARGV0 is not -bash and no --login option is provided). Thus neither .bashrc nor .bash_profile should be sourced. Yet the output of the command clearly shows that .bashrc was sourced. Why?
I used a standard CentOS installation with the standard openssh configuration.
|
According to the manual, it's supposed to do that:
Bash attempts to determine when it is being run with its standard input connected to a network connection, as when executed by
the remote shell daemon,
usually rshd, or the secure shell daemon sshd. If Bash determines it is being run in this fashion, it reads and executes
commands from ~/.bashrc, if that file exists and is readable.
Bash's startup files are weird.
| Why is bash sourcing .bashrc in non-interactive mode when working via ssh? |
1,454,834,906,000 |
I am having a weird problem.
I am not able to ssh to docker container having ip address 172.17.0.61.
I am getting following error:
$ ssh 172.17.0.61
ssh: connect to host 172.17.0.61 port 22: Connection refused
My Dockerfile does contain openssh-server installation step:
RUN apt-get -y install curl runit openssh-server
And also step to start ssh:
RUN service ssh start
What could be the issue?
When I enter into container using nsenter and start ssh service then I am able to ssh. But while creating container ssh-server doesn't seems to start.
What should I do?
|
Container vs. Image
The RUN statement is used to run commands when building the docker image.
With ENTRYPOINT and CMD you can define what to run when you start a container using that image.
See Dockerfile Reference for explanations how to use them.
Services
There is not preinstalled init-system in the containers, so you cannot use service ... start in a container.
Consider starting the process in the CMD statement as foreground process or use an init-system like Phusion or Supervisord.
| openssh-server doesn't start in Docker container |
1,454,834,906,000 |
I've setup public key authentication for enabling SSH connection into my university machine. However, it only logs me in on the local machine and doesn't give me Kerberos credentials which I need for accessing my network folder. This causes problems with tools like git.
Is there a way for me to automatically get Kerberos credentials when connecting through SSH without entering my Kerberos password?
My client machine is OSX 10.6 and my university machine is Ubuntu 12.04
|
Kerberos will work only if you authenticate to Kerberos-enabled server by password. You can:
set up kerberos trust for the incoming user if the user is already authenticated by known realm;
enable GSSAPI forwarding of credentials on ssh client and server ('ssh -K', GSSAPIAuthentication for sshd), this would work if server and client belongs to the same kerberos domain.
| Public Key Auth + Kerberos |
1,454,834,906,000 |
The Terrapin Attack on SSH details a "prefix truncation attack targeting the SSH protocol. More precisely, Terrapin breaks the integrity of SSH's secure channel. By carefully adjusting the sequence numbers during the handshake, an attacker can remove an arbitrary amount of messages sent by the client or server at the beginning of the secure channel without the client or server noticing it."
How would you change the SSH configuration to mitigate this attack?
|
This sounds like a big scarry attack, but it's an easy fix. To mitigate the attack, see my Thwarting the Terrapin Attack article for SSH configuration details. Specifically you need to block the ETM HMACs and ChaCha20 cipher as follows:
For recent RHEL-based Linux systems (Alma, Rocky Oracle, etc), this will work:
# cat /etc/crypto-policies/policies/modules/TERRAPIN.pmod
cipher@ssh = -CHACHA20*
ssh_etm = 0
# update-crypto-policies --set DEFAULT:TERRAPIN
Setting system policy to DEFAULT:TERRAPIN
Note: System-wide crypto policies are applied on application start-up.
It is recommended to restart the system for the change of policies
to fully take place.
Alternatively, you can force AES-GCM which is not vulnerable if your system doesn't have (or doesn't use) update-crypto-policies (eg, as noted by @StephenKitt, Debian/Ubuntu may not use crypto-policies by default):
# cat /etc/ssh/sshd_config
[...]
Ciphers [email protected]
Then test with the testing tool provided by the original researchers.
| How do you mitigate the Terrapin SSH attack? |
1,454,834,906,000 |
For some remote work, I sometimes use X11 forwarding on ssh connections, but usually don't. But, instead remebering to use the -X flag on my ssh connection, I can also set ForwardX11 yes to enable it by default.
My question is, is there any (significant) downside to having X11 forwarding always enabled while not actively using it?
I am using OpenSSH for this, server runs version 5.9, client 6.6.
Edit: I mean enabling it on a per host basis, in $HOME/.ssh/config, not globally.
|
When writing about this topic, I recommend reading through this paper:
http://www.giac.org/paper/gcih/571/x11-forwarding-ssh-considered-harmful/104780
It describes the consequences of letting ForwardX11 option turned on by default in really nice and prosaic way.
But to sum this up, yes, you should turn this off by default and let it on only for trusted servers where you actually need it in your local ~/.ssh/config file.
Untrusted machine is basically each machine, where somebody else has a root access, because that root can access your whole local X11 session, which is basically a thing you don't want from server in remote data-center or for internet facing machine that could be compromised.
| Is there a downside to enabling X11 forwarding in ssh? |
1,454,834,906,000 |
I need to log ssh passwords attempts. I read somewhere you could get this done by patching openssh but I don't know if that is the correct way to get this done.
I am using Arch.
EDIT:
I want to get the passwords people tried to guess to gain access to my system.
It could be with journalctl or get piled in a text file.
If the person let's say types 1234 and tries to get access I want something like
"ssh loggin attempt failed, tried user "admin" with password "1234"
|
What I think is a better answer is to download the LongTail SSH honeypot which is a hacked version of openssh to log username, password, source IP and port, and Client software and version.
The install script is at https://github.com/wedaa/LongTail-Log-Analysis/blob/master/install_openssh.sh
I also do analytics at http://longtail.it.marist.edu
| How can I Log ssh login passwords attempts? |
1,454,834,906,000 |
I am trying to achieve to perform scp via specific NIC.
I read SCP man page but couldn't find required flags.
|
Use BindAddress or BindInterface options using -o switch.
For example:
scp -o BindAddress=x.x.x.x ...
| scp: using specific NIC |
1,454,834,906,000 |
We have RHEL v6.9 server and OpenSSH v5.3p1 is installed on it (confirmed by rpm -q openssh which outputs openssh-5.3p1-123.el6_9.x86_64). After the security testing, we are asked to upgrade OpenSSH to v7.3, to avoid any vulnerabilities.
I have tried yum update openssh and it says
No Packages marked for Update
Any idea, how can I update openssh? Is it even possible to update it to 7.3 on RHEL 6.9?
|
You’re using the latest officially packaged version of OpenSSH on RHEL 6.9, which is still supported (and will be, without an extended support contract, until late 2020):
This means that all known vulnerabilities in your version of openssh are fixed, and newly-discovered vulnerabilities which are discovered in the future will be fixed — there’s no need to upgrade to the latest version of OpenSSH to avoid vulnerabilities.
That’s one of the points of using a supported distribution: you can rely on your distributor to take care of upstream vulnerabilities for you (as long as you keep your systems up-to-date).
To upgrade to OpenSSH 7.4 you’d have to upgrade to RHEL 7, or build it yourself for RHEL 6 (and take on support for future vulnerabilities).
| RHEL 6.9 - Upgrade OpenSSH from 5.3 to 7.3 |
1,454,834,906,000 |
I would like to replace the default 2048 bit host key generated when installing OpenSSH or starting it the first time with one of 4096 bit length.
This leads to two questions:
Does OpenSSH allow running with a 4096 bit RSA host key (for SSH2 obviously)?
How can ssh-keygen be convinced not to prompt for a passphrase?
The version of OpenSSH I am running is 6.6p1.
|
Whatever key-length is supported in ssh-keygen most likely would work with sshd as well. Besides that, you should generate your host-keys with ssh-keygen -h anyways, so if ssh-keygen isn't totally dumb, it should inform you if the desired key-length is not supported for host keys.
The passphrase could be specified with -N; if you don't want the key to be encrypted, just specify an empty one (thus just hitting Enter if it prompts you would have the same effect).
| Generate own (stronger) RSA host key for OpenSSH? |
1,454,834,906,000 |
I have the following network topology:
workstation <-> network_device <-> authentication_server
When I log in to network_device from workstation over SSH, then network_device checks with TACACS+ authentication_server if I have a permission to log in, what are my access rights for that network_device, etc. When I execute ssh -o LogLevel=quiet network_device in workstation, then I do not see the network device banner, but I do see the following prompt:
$ ssh -o LogLevel=quiet network_device
TACACS authentication!
Password:
$
This TACACS authentication! string is set by authentication_server. When I execute ssh -vvv -o LogLevel=quiet network_device, then I see that this banner and password prompt seem to have different message IDs. Banner:
debug3: receive packet: type 53
debug3: input_userauth_banner
*************************************************
* Access limited to Authorized Users only *
*************************************************
Password prompt:
debug3: receive packet: type 60
debug2: input_userauth_info_req
debug2: input_userauth_info_req: num_prompts 1
TACACS authentication!
Password:
Does OpenSSH client LogLevel option work in a way that it simply filters certain message IDs depending on LogLevel value? Manual page does not explain, how exactly LogLevel decides what to show:
LogLevel
Gives the verbosity level that is used when logging messages from ssh(1). The possible values are: QUIET, FATAL, ERROR, INFO, VERBOSE, DEBUG, DEBUG1, DEBUG2, and DEBUG3. The default is
INFO. DEBUG and DEBUG1 are equivalent. DEBUG2 and DEBUG3 each specify higher levels of verbose output.
|
The bulk of what you want to know is in log.c in the OpenSSH source. There is an enum variable called log_level. (Enum meaning it acts like a number under the hood, but each level is associated with an easy-to-understand name.) This log_level variable is set globally and acts as a mask for hiding logs you aren't interested in.
Then whenever something is logged, the message is also associated with an importance level, and the message + importance are given to a function called do_log.
In the do_log function, we see the following check:
if (!force && level > log_level)
return;
It means that if the message is less important than the configured log level, this message is elided from the log output.
The do_log function does additional processing, eg using the importance level of the message to decide whether to prefix the output with fatal or whatever is appropriate.
| How does OpenSSH LogLevel option work? |
1,454,834,906,000 |
Is it possible to set the AuthorizedKeysFile setting explicitly such that it covers the following cases:
standard user under /home/%u/.ssh/authorized_keys
system user under /var/lib/%u/.ssh/authorized_keys
root user under /root/.ssh/authorized_keys
My question is, is there a variable that contains the user directory as specified in the Name Service Switch?
|
You have indicated that you would accept using the the user's home directory to be used as the base for .ssh/ - whether the user is a real user, system user or root.
I'm inferring this from your question:
I tried to solve this by changing my /etc/ssh/sshd_config to
AuthorizedKeysFile ~/.ssh/authorized_keys
This failed, because sshd was checking /root/.ssh/authorized_keys.
If you take a quick look at the manual for sshd_config you will see this:
AuthorizedKeysFile
Specifies the file that contains the public keys that can be used for user authentication. AuthorizedKeysFile may contain tokens of the form %T which are substituted during connection setup. The following tokens are defined: %% is replaced by a literal '%', %h is replaced by the home directory of the user being authenticated, and %u is replaced by the username of that user. After expansion, AuthorizedKeysFile is taken to be an absolute path or one relative to the user's home directory. The default is ''.ssh/authorized_keys''.
In my default setup I have have a line commented out:
# AuthorizedKeysFile %h/.ssh/authorized_keys
This means that (at least for Ubuntu and Debian distributions of OpenSSH) you are actually asking for the default configuration! That may be as good a reason as any for the down-votes.
| How can I provide the authorized_keys path in sshd that allows normal users, system users, and a root user? |
1,454,834,906,000 |
Problem: When running the ssh-keyscan command in cron it emails me the output of ssh-keyscan every day. The email simply contains the following.
# <hostname> SSH-2.0-OpenSSH_5.3
My (simplified) cron job:
host=`uname -n`
SSHKey=`ssh-keyscan $host`
echo $SSHKey >> /root/.ssh/known_hosts
My question: How do I prevent ssh-keyscan from writing anything to the shell?
|
redirect stderr into /dev/null
host=`uname -n`
SSHKey=`ssh-keyscan $host 2> /dev/null`
echo $SSHKey >> /root/.ssh/known_hosts
| Prevent ssh-keyscan from generating output |
1,454,834,906,000 |
I have read numerous solutions to this problem, but none seem to apply to what I'm seeing. Most focus on directory permissions, but those appear to be correct in this case. TL;DR: Two Centos7 servers with the same home directory; one's sshd is not allowing publickey authentication even though it is enabled.
I have two centos7 servers, let's call them centos-a and centos-b. Home directories are mounted via NFS, so the .ssh directories are identical between both (confirmation of this below). I can ssh from centos-a to centos-a, but not to centos-b. I can ssh from centos-b to centos-a and to centos-b.
ssh-ability
centos-a
centos-b
centos-a
YES
NO
centos-b
YES
YES
[myuser@centos-a ~]$ ls -la ~/.ssh
total 16
drwx------. 1 myuser domain users 0 Jul 6 11:45 .
drwx------. 1 myuser domain users 0 Jul 7 13:44 ..
-rw-------. 1 myuser domain users 1212 Jul 6 12:02 authorized_keys
-rw-------. 1 myuser domain users 1675 Jul 6 11:45 id_rsa
-rw-r--r--. 1 myuser domain users 402 Jul 6 11:45 id_rsa.pub
-rw-r--r--. 1 myuser domain users 1119 Jul 6 17:49 known_hosts
[myuser@centos-a ~]$ md5sum ~/.ssh/*
65b4fdf2d59cee3ae45b8480454453ec /home/myuser/.ssh/authorized_keys
fa3e9fc5a8ff08787ff2ba8f979da24e /home/myuser/.ssh/id_rsa
dca36ab3ec342423c5eca588f2ad5678 /home/myuser/.ssh/id_rsa.pub
f67bc94bc7a30b9876e3027b24f893d8 /home/myuser/.ssh/known_hosts
[myuser@centos-a ~]$ ssh centos-a hostname
centos-a
[myuser@centos-a ~]$ ssh centos-b hostname
myuser@centos-b's password:
[myuser@centos-b ~]$ ls -la ~/.ssh
total 16
drwx------. 1 myser domain users 0 Jul 6 11:45 .
drwx------. 1 myser domain users 0 Jul 7 13:44 ..
-rw-------. 1 myser domain users 1212 Jul 6 12:02 authorized_keys
-rw-------. 1 myser domain users 1675 Jul 6 11:45 id_rsa
-rw-r--r--. 1 myser domain users 402 Jul 6 11:45 id_rsa.pub
-rw-r--r--. 1 myser domain users 1119 Jul 6 17:49 known_hosts
[myuser@centos-b ~]$ md5sum ~/.ssh/*
65b4fdf2d59cee3ae45b8480454453ec /home/myuser/.ssh/authorized_keys
fa3e9fc5a8ff08787ff2ba8f979da24e /home/myuser/.ssh/id_rsa
dca36ab3ec342423c5eca588f2ad5678 /home/myuser/.ssh/id_rsa.pub
f67bc94bc7a30b9876e3027b24f893d8 /home/myuser/.ssh/known_hosts
[myuser@centos-b ~]$ ssh centos-b hostname
centos-b
[myuser@centos-b ~]$ ssh centos-a hostname
centos-a
As shown above, the permissions on the .ssh directory appears to be correct (and, regardless, is identical between both machines).
ssh -vvv on the failing ssh shows:
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
...
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
...
debug1: Host 'centos-b' is known and matches the ECDSA host key.
...
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-keyex
debug3: remaining preferred: gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-keyex
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug2: we did not send a packet, disable method
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:1211402155)
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:1211402155)
debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/myuser/.ssh/id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/myuser/.ssh/id_dsa
debug3: no such identity: /home/myuser/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/myuser/.ssh/id_ecdsa
debug3: no such identity: /home/myuser/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/myuser/.ssh/id_ed25519
debug3: no such identity: /home/myuser/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
myuser@centos-b's password:
Contrast this to what I see going from centos-b to centos-a, which works:
...
debug1: Unspecified GSS failure. Minor code may provide more information
Server not found in Kerberos database
debug3: send packet: type 50
debug2: we sent a gssapi-with-mic packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/myuser/.ssh/id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug2: input_userauth_pk_ok: fp SHA256:nAO5pVOzqUQzEUSEBN37WKp6ADs9Sk4rfTRGmk0FHEY
debug3: sign_and_send_pubkey: RSA SHA256:nAO5pVOzqUQzEUSEBN37WKp6ADs9Sk4rfTRGmk0FHEY
debug3: send packet: type 50
debug3: receive packet: type 52
debug1: Authentication succeeded (publickey).
I've enabled sshd log messages in /etc/ssh/sshd_config and restarted the service
# Logging
SyslogFacility AUTH
SyslogFacility AUTHPRIV
LogLevel INFO
But there are no additional useful messages in either /var/log/secure or /var/log/messages.
Interestingly the ssh from centos-b to centos-b is using gssapi authentication. If I force it to use publickey it fails:
[myuser@centos-b ~]$ ssh -vvv -o PreferredAuthentications=publickey centos-b hostname
...
debug1: Offering RSA public key: /home/myuser/.ssh/id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
...
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
and I see in /var/log/messages:
Jul 7 13:52:10 centos-b sshd[23266]: Connection closed by 192.168.1.100 port 48064 [preauth]
pubkey is enabled:
[root@centos-b ssh]# sshd -T | grep -i pub
pubkeyauthentication yes
pubkeyacceptedkeytypes [email protected],ecdsa-sha...
The sshd_config is a stock Centos7 sshd_config, and is identical between centos-a and centos-b (verified by piping the following command through md5sum on both machines
[root@centos-b ssh]# grep -v -e '^#' -e '^$' /etc/ssh/sshd_config
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
Subsystem sftp /usr/libexec/openssh/sftp-server
Any suggestions for what I'm missing?
|
Some additional googling revealed to me that the issue was with SELinux being enabled on the new systems I've configured. In my case setting this to permissive solves my issue.
# getenforce
Enforcing
# setenforce 0
# getenforce
Permissive
That might not be the right solution for people who require SELinux in their environment. The permanent change involves updating /etc/selinux/config.
| ssh publickey authentication failure: receive packet: type 51. sshd is not accepting publickey auth at all |
1,454,834,906,000 |
I have multiple keys (some private, some public) and I want to get information about them (their length, their type, anything else). Is that possible?
|
Based on the question tags, I’m assuming you’re asking about SSH keys.
For public keys, you can ask ssh-keygen:
ssh-keygen -lf /path/to/key.pub
This will show you the key type (at the end of the output), its length (at the beginning), and its fingerprint.
For private keys, you can ask openssl, but you’ll need to know the type:
openssl rsa -text -noout -in /path/to/id_rsa
You’ll need to provide the key’s passphrase, if any; you’ll then see the key size and all its contents.
| Read key properties |
1,454,834,906,000 |
I am trying to have a local Unix domain socket, say, ~/docker.sock. I want it to proxy everything to a remote Unix domain socket running elsewhere over SSH. (You can find a diagram of what I’m trying to do below).
OpenSSH supports this (an example here). For instance, this command will proxy MySQL client connections on a remote server to my local instance:
ssh -R/var/run/mysql.sock:/var/run/mysql.sock -R127.0.0.1:3306:/var/run/mysql.sock somehost
But this is not how I want it to be like. It forwards the traffic that comes to the remote socket to my local socket (I want it the other way).
|
The man page for ssh offers two complementary options: -R for remote forwarding to local, and -L for local forwarding to remote.
In your case just use -L instead of -R.
| Proxying traffic on local unix to a remote unix socket over SSH |
1,454,834,906,000 |
In my current work setup, I have:
Windows 7 laptop
Ubuntu virtual host / SSH
Windows 2k8 guest
I'd like to be able to RDP from my laptop into the Windows guest without having to open additional ports or have Windows RDP directly exposed to the internet.
If I forwarded localhost:10467 to ubuntuhost:22 using Putty, can OpenSSH forward this connection to windowsguest:3389 or do I need to start looking at VPN solutions?
|
With a tunnel SSH, you can do something like that:
laptop Ubuntu server guest
____ 10467 22 _____ ? 3389_____
| |___________________| |__________| |
|____| \ |_____| |_____|
\
\__SSH connection
But take care that only the connection between laptop and Ubuntu server will be encrypted. And the port 3389 has to be opened so that's not what you're looking for. You should go with a VPN if you want to do RDP with a server reachable from Internet.
If the Ubuntu server is in the same protected Local Area Network (LAN) than windowsguest, then it's ok. You just have to open your 3389 port on windowsguest and close it on your firewall, so that it remains protected. Even if windowsguest is reachable from Internet, it won't use the same interface to communicate with the Ubuntu server and with the rest of the world. So, just make sure the 3389 port is closed on the Internet interface and open on the LAN interface.
With the openssh program, the commandline would look like
ssh -L 10467:windowsguest:3389 user@ubuntuhost.
The same option exists for PuTTY.
In this window:
select "Local" option
enter "windowsguest:3389" as destination
enter "10467" as source port
leave "Auto" option
This image was taken from http://howto.ccs.neu.edu/howto/windows/ssh-port-tunneling-with-putty/ which is a pretty good tutorial for port tunneling with SSH.
| Can an OpenSSH server forward inbound traffic to another server? |
1,454,834,906,000 |
Is it possible to configure OpenSSH (or any other standard sshd) to accept any key offered by a connecting client?
EG ssh -i ~/arbitraryKey hostname grants a login shell while ssh hostanme doesn't.
I ask because of a half remembered anecdote about a misconfigured server but I've had a look and I couldn't find anything that would actually let this happen without some form of deliberate hacking of the daemon. (Recompiling etc)
|
Configuring an SSH server to accept any password would be easy with PAM — put pam_permit on the auth stack, and voilà. The possibility of misconfiguring such an open system is inherent to the flexibility of PAM — since it lets you chain as many tests as you want, the possibility of doing 0 tests is unavoidable (at least without introducing weird exceptions that wouldn't cover all cases).
Key authentication doesn't go through PAM, and there's no configuration setting for “accept any key”. That would only be useful in extremely rare cases (for testing or honeypots), so it isn't worth providing it as an option (with the inherent risk of misconfiguration).
| Accept any private key for authentication |
1,454,834,906,000 |
I'm a bit confused what the "correct" path for ssh's systemwide known_hosts file is..
the man ssh says /etc/ssh/ssh_known_hosts
whereas SSH Host Key - What, Why, How talks about /etc/ssh/known_hosts.
Are both locations valid? Is the difference a historic artefact? Is it distribution specific? Which file path should be used?
|
For OpenSSH, its man page is the canonical documentation. According to ssh(1) - OpenBSD manual pages, /etc/ssh/ssh_known_hosts is the official path for the “systemwide list of known host keys”. This applies to all releases of OpenSSH and is not specific to any one distribution – or OS for that matter.
SSH.COM is the website for SSH Communications Security, a commercial company set up by the original designer of the SSH protocol and writer of the first implementation. It has no direct relationship with the OpenSSH project which is maintained by a group of OpenBSD developers based on a fork of an early release of the original SSH program.
I don’t know where SSH Communications Security got /etc/ssh/known_hosts from (presumably their own or the original implementation) but as a third-party source of information, it is not relevant to users of OpenSSH. Out of interest, I checked the earliest version (rev 1.1) of the OpenSSH man page and it had historically been using yet another (slightly different) path, /etc/ssh_known_hosts.
| openssh-client - what is correct location for global known_hosts file? |
1,454,834,906,000 |
Short Question
I'm assuming that ssh-keygen -r hostname uses a default public key. I would have thought that it would default to ~/.ssh/id_rsa.pub, but that does not appear to be the case. So what is it doing?
Long Version
My experience with the OpenSSH command-line utilities is that they either prompt the user for any missing arguments or fall back to standard default values. But for ssh-keygen -r this does not appear to be the case. When I run the ssh-keygen -r command without specifying a public key (e.g. ssh-keygen -r hostname), I get the following output:
no keys found.
I would expect it to default to my public key, e.g. ~/.ssh/id_rsa.pub. However, this does not appear to be the case, since when I pass in this public key explicitly (e.g. ssh-keygen -r hostname -f ~/.ssh/id_rsa.pub) I instead get output of the following form:
hostname IN SSHFP 1 1 5d6c87ef4e8f4f59974f05723ff3dc0cffc9c4b4
hostname IN SSHFP 1 2 8fa151e7f3ba43fa89c240ab236f0313aea1fe9f9e9f4e5b8f084ca0008399ed
Moreover, the man page for ssh-keygen shows the following syntax for the ssh-keygen -r command:
ssh-keygen -r hostname [-f input_keyfile] [-g]
Since the -f input_keyfile flag is denoted as being optional, I would expect ssh-keygen to do something other than just print an error message.
So, if ssh-keygen -r hostname does not use ~/.ssh/id_rsa.pub as its default public key, and it doesn't prompt the user to specify a public key, then what is it doing? Is it defaulting to some other path? If so, what path is that?
NOTE: I'm running OpenSSH Version 7.6 on macOS High Sierra (Mac OS X Version 10.13.6).
|
ssh-keygen -r generates a SSHFP record. That's something you put in a DNS entry to say indicate the host key corresponding to a host name. This allows someone who wants to log into your machine to know what host key to expect, assuming that they trust the DNS record (which in practice means that it must be obtained using DNSSEC).
So naturally ssh-keygen -r looks for the host key of your machine. It isn't interested in a user key — if you force it to read a user key, it might work, but the result isn't useful. ssh-keygen -r looks at /etc/ssh_host_*_key.pub, or wherever the SSH server has been configured to look for the host's keys. If you don't have an SSH server set up on your machine, you have no use for an SSHFP record, so it isn't a problem that ssh-keygen -r doesn't find a key.
| What does `ssh-keygen -r` do if a public key is not specified? |
1,454,834,906,000 |
How can I specify the order in which OpenSSH's SSH client (OpenSSH_7.5p1, OpenSSL 1.0.2k 26 Jan 2017; Git for Windows v2.11.1) offers the public/private key pairs to a SSH compliant daemon such as Apache Mina SSHD (Gerrit Code Review service). My intention is to try to authenticate with an Ed25519 public/private key pair before falling back to RSA.
Given the following standard Ed25519 and RSA public/private key pairs below the user's home directory:
~/.ssh/id_ed25519{,.pub}
~/.ssh/id_rsa{,.pub}
and the following Host sections in the user's SSH configuration file (~/.ssh/config):
Host foobar foobar.example.com
Hostname foobar.example.com
IdentityFile ~/.ssh/id_ed25519
Host *
IdentityFile ~/.ssh/id_ed25519
IdentityFile ~/.ssh/id_rsa
when testing the SSH connection in debug mode:
$ ssh -Tv bob@foobar
debug1: Reading configuration data ~/.ssh/config
debug1: ~/.ssh/config line 49: Applying options for foobar
debug1: ~/.ssh/config line 63: Applying options for *
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: ~/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering ED25519 public key: ~/.ssh/id_ed25519
debug1: Server accepts key: pkalg ssh-ed25519 blen 51
debug1: Authentication succeeded (publickey).
I can see that OpenSSH's SSH client offers the RSA public/private key pair first. But why not first Ed25519?
|
Add IdentitiesOnly option. Without this option SSH tries first default ssh-keys available: id_rsa, id_dsa, id_ecdsa. To change this behaviour replace your config with this one:
Host foobar foobar.example.com
Hostname foobar.example.com
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Host *
IdentityFile ~/.ssh/id_ed25519
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
| OpenSSH's SSH client not respecting order of IdentityFile settings |
1,454,834,906,000 |
How do I configure sshd to 1) require public key and 2) require a password for login? Note that I am not referring to the symmetric encryption of the client's key here. I am referring to a server-side password.
Is this possible?
|
The linked answer in the other answer is really old and there are many changed things since then. So once again:
If you read through the manual page for sshd_config(5), there is option AuthenticationMethods, which takes the list of methods you need to pass before you are granted access. Your required setup is:
AuthenticationMethods publickey,password
This method should work all the current Linux systems with recent openssh (openssh-6, openssh-7).
Older systems
The only exception I know about is RHEL 6 (openssh-5.3), which requires setting different option with same values (as described on information security answer):
RequiredAuthentications2 pubkey,password
| How do I configure sshd to 1) require public key _and_ 2) require a password for login? |
1,454,834,906,000 |
I have my DNS search path set to ".intranet", ie, /etc/resolv.conf contains:
search intranet
When I SSH to a host using a FQDN, like "mailserver.intranet", it adds an entry for "mailserver.intranet" to ~/.ssh/known_hosts. If I later SSH to this same host but using the simple "mailserver" name, SSH adds another entry to known_hosts for "mailserver".
Is it possible to make SSH always use FQDN in known_hosts to avoid this duplicity?
|
You could use aliases for host keys:
Host <hostname>*
hostname <fqdn>
HostKeyAlias <alias>
Your key will be saved to known_hosts as "alias" instead of "hostname" either short or long, the downside is you have to write an entry for each one of your hosts.
Please note the '*' after the hostname at the first line, it's needed for matching both the short and long hostname.
| Avoiding duplicate entries in ~/.ssh/known_hosts |
1,454,834,906,000 |
I'm sure this has been answered before, but I could not locate the answer with Google, and this search. I currently only allow shared key authentication for openssh server on my box. However, I would like to be able to use password auth, when I am connecting locally, via my internal (192.168.1.x) subnet.
Is it possible to use a per-host authentication method in OpenSSH? Thanks!
|
Use a Match directive in /etc/sshd_config.
PasswordAuthentication No
Match Address 192.168.1.0/24
PasswordAuthentication yes
You can restrict this to a few users (who you trust not to choose terrible passwords), for better security.
PasswordAuthentication No
Match Address 192.168.1.0/24 User joe,bob
PasswordAuthentication yes
| Use different authentication methods for OpenSSH server depending on client IP |
1,454,834,906,000 |
Does gnome-keyring support SSH private keys that are saved in the newer OpenSSH file format? Will Gnome Keyring automatically import those private keys?
In more detail: When generating a SSH private key, ssh-keygen can save the private key in the newer OpenSSH format (rather than the "more compatible PEM format"). With this format, the private key file begins with "-----BEGIN OPENSSH PRIVATE KEY-----".
I just generated a new RSA private key for SSH and saved it in the newer format, using ssh-keygen -t rsa -b 3072 -o -a 16. Now Gnome Keyring doesn't seem to be able to load that private key. In contrast, everything seems to work fine when using ssh-agent.
When using Gnome Keyring with this new private key, I see the following error messages in /var/log/messages:
gnome-keyring-daemon[10904]: invalid or unrecognized private SSH key: [key id]
gnome-keyring-daemon[10904]: signing of the data failed: The operation failed
and when I try to run ssh, I see the following error message in my terminal:
sign_and_send_pubkey: signing failed: agent refused operation
If it's relevant, I'm using Fedora 25 with MATE, with gnome-keyring-3.20.0-1.fc25.x86_64.
|
Things have changed slightly now. As a result GNOME 3.28 now wraps OpenSSH's ssh-agent, which gives it the same level of support as OpenSSH.
Reference - Archlinux wiki - GNOME/Keyring
Known issues
Cannot handle ECDSA and Ed25519 keys
As of January 2018, GNOME Keyring doesn't handle ECDSA nor
Ed25519 keys. You can turn to other SSH agents if you need
support for those.
Note: As of GNOME 3.28, gnome-keyring replaced its SSH
agent implementation with a wrapper around the ssh-agent tool
that comes with openssh. As a result, any type of key
supported by the upstream ssh-agent is now also supported by
gnome-keyring, including ECDSA and Ed25519 keys.
If you still find that you're behind this particular version this Gist shows how you can use keychain to workaround this issue, titled: SSH with ed25519 (curve25519) + GNOME-KeyRing.
References
new openssh key format and bcrypt pbkdf
| Does Gnome Keyring support new-format OpenSSH private keys? |
1,454,834,906,000 |
On my vanila Arch Linux system, I can send to local tmux-session (session main) using:
$ tmux send -t main.0 'echo asdf' ENTER
I can also send commands to a remote machine using ssh: (just for the demonstration, I'm using localhost):
$ ssh garid@localhost "ls /home"
I want to send command to tmux-session in remote-machine from my terminal (something like following):
$ ssh -t garid@localhost "tmux send -t main.0 'echo asdf' ENTER"
But it outputs the following error:
error connecting to /tmp/tmux-1000/default (No such file or directory)
Connection to localhost closed.
What am I doing wrong here?
|
In the comments, we've confirmed that the intended command,
ssh remote "tmux send -t main.0 'echo asdf' ENTER"
... works when remote is not the local host.
We have also confirmed that the reason the command fails when connecting to localhost is that the TMUX_TMPDIR variable is unset in the SSH session. This environment variable is used by tmux to determine where a directory containing its control socket should be created. If the variable is unset, the utility will use /tmp.
The variable is unset when you execute tmux via ssh because the session is a non-interactive non-login session. As such, it does not source your ~/.config/shell/profile file which sets the TMUX_TMPDIR variable to something other than /tmp. This file is pulled in by LARBS, which you use, but of which I know nothing.
You now have a few possible ways to move forward:
Do nothing; The intended target of the ssh+tmux command was never the local host.
Ensure that the TMUX_TMPDIR variable is set correctly when calling the command on localhost; You may do this with
ssh localhost "env TMUX_TMPDIR='$TMUX_TMPDIR' tmux send -t main.0 'echo asdf' ENTER"
... but it would assume that the value of the variable locally is the correct value for the other host, so it would be unlikely to be a generic solution. Connecting with ssh to localhost is such an unusual thing to do anyway, so rather than doing it this way, loop back to the first point and don't do anything about it, or ...
Reset the value of TMUX_TMPDIR to the default /tmp locally by modifying ~/.config/shell/profile (set the variable to /tmp or comment out the assignment completely); I don't know how this may play with LARBS, though.
| How to send a command to tmux-session of remote-device (using ssh) |
1,454,834,906,000 |
I'm using
ControlMaster auto
ControlPath ~/.ssh/tmp/%l_%r@%h:%p
in my ~/.ssh/config to open multiple sessions using the same connection when accessing a host via SSH.
That works fine for most use cases, but doesn't allow me to connect to the same hostname via IPv4 and IPv6 at the same time; all additional connections use the control socket created by the first connection because the ControlPath doesn't allow to distinguish between IPv4 and IPv6 connections.
Is there a way to have separate control sockets for IPv4 and IPv6 connections (perhaps by finding a way to use the remote IP rather then the remote hostname in the socket path)?
EDIT #1
I just remembered the Match option available in ssh_config and sshd_config files and tried:
Match AddressFamily inet
ControlPath ~/.ssh/tmp/%l_%r@%h:%p.inet
Match AddressFamily inet6
ControlPath ~/.ssh/tmp/%l_%r@%h:%p.inet6
Unfortunately, that fails with "Unsupported Match attribute AddressFamily" when I try to connect to any host, so I'm back to square one…
|
I've split my answer into two separate answers so you can up/downvote the "wrapper" and "patch" approaches separately.
Solution 1: Write a wrapper function
ssh ()
{
controlpath=""
for argument in $@
do
if [[ "$argument" = "-"*"4"* ]]
then
controlpath="~/.ssh/tmp/%l_%r@%h:%p.inet"
fi
if [[ "$argument" = "-"*"6"* ]]
then
controlpath="~/.ssh/tmp/%l_%r@%h:%p.inet6"
fi
done
if [ -n "$controlpath" ]
then
/usr/bin/ssh -o "ControlPath=$controlpath" $@
else
/usr/bin/ssh $@
fi
}
This wrapper function will instruct ssh to create separate control sockets for ssh host, ssh -4 host, and ssh -6 host.
It might not parse something like ssh -464466 host correctly (even though that's technically allowed), but it should be the easiest workaround for simple scenarios.
| How to make SSH's `ControlPath` distinguish between IPv4 and IPv6? |
1,454,834,906,000 |
I have an AIX server which suddenly stopped servicing SSH connections. When I try to start the service through startsrc -s sshd it says:
0513-059 The sshd Subsystem has been started. Subsystem PID is 258300.
However, right after issuing the command, the services status shows up as inoperative:
sshd ssh inoperative
The init scripts are well located and throw the same result as above.
EDIT: Here's the odmget command output:
SRCsubsys:
subsysname = "sshd"
synonym = ""
cmdargs = "-D"
path = "/usr/sbin/sshd"
uid = 0
auditid = 0
standin = "/dev/console"
standout = "/dev/console"
standerr = "/dev/console"
action = 1
multi = 0
contact = 2
svrkey = 0
svrmtype = 0
priority = 20
signorm = 15
sigforce = 9
display = 1
waittime = 20
grpname = "ssh"
When trying to start the service manually, the following error appears:
exec(): 0509-036 Cannot load program /usr/sbin/sshd because of the following errors:
0509-150 Dependent module libz.a(libz.so.1) could not be loaded.
0509-022 Cannot load module libz.a(libz.so.1).
0509-026 System error: A file or directory in the path name does not exist.
Any help would be greatly appreciated.
|
Looks like libz.so.1 is missing on your system.
| sshd process inoperative |
1,454,834,906,000 |
I'm looking to install Debian over my Android installation so as to be able to use openssh-server, as it's so much better than Dropbear. Is there an easy way to do this, or just to simply install openssh-server on my phone? I'm running Android 2.3.X on a Google Nexus One.
|
If you want to run an ssh server on a rooted phone, you can install SSHDroid.
You can build a Debian image via deboostrap. Debian runs on ARM so you wont have problems building an image for that arquitechture. There is an interesting howto writen for SG1, you could try it out.
| Is there a way to run an ssh server on an Android device? |
1,454,834,906,000 |
In the environment I work in, we use tunnels to SSH to various servers. For example, I'll 'ssh -p XXXXX username@localhost' to reach the server.
If the port was always the same, I could do this, and I'd be done:
Host somehost
User bryan
Hostname localhost
Port 12345
ProxyCommand ssh -p 2218 [email protected] -W %h:%p
However, the port used can and will change if the tunnel goes down and comes back up. This isn't something I have the ability to change - it's built into the infrastructure. So, I wrote a program to find the current port. But I don't know how to either:
a) Run that program and use the output for the %p variable; or
b) Run a cron job on first.server.com to write out a text file with the port in it, or set an environment variable, or something.
In effect, I want to do this. Is it possible?
Host somehost
User bryan
Hostname localhost
Port `sh get_port_for_somehost.sh`
ProxyCommand ssh -p 2218 [email protected] -W %h:%p
The only thing I can think of right now is to run a program on my laptop which rewrites my .ssh/config after going and querying what the ports currently are, but I'd prefer not to do that.
|
It is not possible to write a script in the configuration file to pull a variable for port number.
But you can write a bash function to get the port for you and place it into the correct place. For example place the following to the ~/.bashrc:
function ssh-dynamic() {
PORT=`sh get_port_for_somehost.sh`
exec ssh -p "$PORT" somehost "$@"
}
where the other configuration may stay in the ~/.ssh/config.
| .ssh/config ProxyCommand with a variable port |
1,454,834,906,000 |
SOLVED!
The machine is a Dell Poweredge system which ran what they call iDRAC in the background - iDRAC in its turn ran a SSH-server which conflicted with the one I installed in Debian. The solution for me was just to disable iDRAC since I don't use it, and I'm glad I don't. I have no idea how that conflict should've been solved.
Just installed Debian Stretch on a machine. Minimal install haven't done pretty much anything but installing openssh-server and setting up my network interface. The problem I have seems to be related to the networking service.
Straight from boot I'm not able to connect to my server via SSH remotely. The server has internet connection at this time, I'm able to ping it and ping from it. At connection it starts out good but then a popup asks for a password for the user, typing in the password doesn't work - should already have been sent by the client anyway. When I run systemctl restart networking.service on the server SSH suddenly starts working.
openssh-server is running with default configurations.
My SSH client(Bitvise) log says:
15:08:26.493 Started a new SSH2 session.
15:08:26.493 Connecting to SSH2 server 171.xxx.xxx.xxx:22.
15:08:26.493 Connection established.
15:08:26.681 Server version: SSH-2.0-OpenSSH_5.8 <----
15:08:26.681 First key exchange started.
15:08:27.289 Received a new host key from the server. Algorithm: xxxxxxxxxxx
15:08:27.320 First key exchange completed using ecdh-sha2/nistp521. xxxxxxxxxxx
15:08:27.320 Attempting password authentication.
15:08:28.724 Authentication failed. Remaining authentication methods: 'password'.
15:08:30.581 Authentication aborted on user's request.
15:08:30.596 The SSH2 session has been terminated.
Note the server version SSH-2.0-OpenSSH_5.8
telnet 174.xxx.xxx.xxx 22
responds with SSH-2.0-OpenSSH_5.8
On the server SSH seems to be running just fine:
systemctl status sshd.service
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2017-06-28 11:16:52 CEST; 4h 10min ago
Main PID: 598 (sshd)
Tasks: 1 (limit: 7372)
CGroup: /system.slice/ssh.service
└─ 598 /usr/sbin/sshd -D
systemd[1]: Starting OpenBSD Secure Shell server...
sshd[598]: Server listening on 0.0.0.0 port 22.
sshd[598]: Server listening on :: port 22.
systemd[1]: Started OpenBSD Secure Shell server.
Status for networking.service shows this
systemctl status networking.service
● networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2017-06-28 11:16:49 CEST; 4h 10min ago
Docs: man:interfaces(5)
Process: 471 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=0/SUCCESS)
Process: 335 ExecStartPre=/binsh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exclude=lo)" ] && udevadm settle (code=exited, status=0/SUCCESS)
Main PID: 1120 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 7372)
CGroup: /system.slice/networking.service
systemd[1]: Starting Raise network interfaces...
systemd[1]: Started Raise network interfaces.
After restarting the network service
systemctl restart networking.service
After running this command SSH all of a sudden starts working.
SSH client log says:
15:08:57.179 Started a new SSH2 session.
15:08:57.179 Connecting to SSH2 server 171.xxx.xxx.xxx:22.
15:09:00.205 Connection established.
15:09:00.205 Server version: SSH-2.0-OpenSSH_7.4p1 Debian-10 <----
15:09:00.205 First key exchange started.
15:09:00.283 Received a new host key from the server. Algorithm: xxxxxxxxxxx
15:09:00.314 First key exchange completed using ecdh-sha2/nistp521. xxxxxxxxxxx
15:09:00.314 Attempting password authentication.
15:09:00.330 Authentication completed.
15:09:00.470 Terminal channel opened.
The odd thing here is that now it shows server version SSH-2.0-OpenSSH_7.4p1 Debian-10
telnet 174.xxx.xxx.xxx 22
responds with SSH-2.0-OpenSSH_7.4p1 Debian-10
systemctl status sshd.service shows same as before
Status for networking.service gives shows this
systemctl status networking.service
● networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2017-06-28 15:12:49 CEST; 1min 12s ago
Docs: man:interfaces(5)
Main PID: 1292 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 7372)
CGroup: /system.slice/networking.service
systemd[1]: Starting Raise network interfaces...
systemd[1]: Started Raise network interfaces.
/etc/network/interfaces
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
auto eno1
iface eno1 inet static
address 174.xxx.xxx.29
netmask 255.255.255.248
gateway 174.xxx.xxx.25
broadcast 174.xxx.xxx.31
dns-nameservers 8.8.8.8 8.8.4.4
/etc/hosts
127.0.0.1 localhost.localdomain localhost
127.0.1.1 boris.secnet.sec boris
/etc/hostname
boris
/etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
Made a resolv.conf and added nameservers there. Had issues with just having them in /etc/network/interfaces. Tried both with and without the resolv.conf and specifying them in /etc/network/interfaces.
NetworkManager enabled/disabled, no difference in behaviour.
No firewall.
The server is connected straight to the internet, same goes for my client machine.
So, what happens with SSH when systemctl restart network.services is invoked? Why does it throw back a different SSH server versions before and after the networking service is restarted?
Why won't the networking service do, whatever it does when restarting it manually, at boot?
I'm completely lost on this one, been testing for days. Worked perfectly fine with Debian Wheezy on the same net and interface settings before I upgraded. Made a full reinstall, formatted disk and installed Stretch.
Does anyone have a clue about what the problem might be? Or how to troubleshoot.
|
SOLVED! The machine is a Dell Poweredge system which ran what they call iDRAC in the background - iDRAC in its turn ran a SSH-server which conflicted with the one I installed in Debian. The solution for me was just to disable iDRAC since I don't use it, and I'm glad I don't. I have no idea how that conflict should've been solved.
| SSH won't work before manually restarting networking.service |
1,454,834,906,000 |
I'm trying to connect to my Redhat AWS instance with a port other than 22.
This command works:
ssh -i my.pem -p 22 [email protected]
But this command does not:ssh -i my.pem -p 8157 -vvv [email protected]
The second command outputs:
OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to X.X.X.X port 8157.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file my.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file my.pem-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
but then just hangs. On the server I'm trying to connect to, however, when I run nc -l 8157 I can see
SSH-2.0-OpenSSH_7.6
If I take out the -vvv part I just get a quick "Connection refused" error.
When I log into the machine and run ssh -p 8157 -vvv ec2-user@localhost
I get the following output:
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug2: resolving "localhost" port 8157
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 8157.
debug1: connect to address 127.0.0.1 port 8157: Connection refused
ssh: connect to host localhost port 8157: Connection refused
Any idea what's going on?
|
This command works: ssh -i my.pem -p 22 [email protected]
But this command does not: ssh -i my.pem -p 8157 -vvv [email protected]
Your other side may have opened port in the firewall, but...
Since port 22 works, your server listens on that port.
Re-configure your server to listen on whatever port you wish.
You can do that in the file:
/etc/ssh/sshd_config
With the following setting:
Port 8157
Don't forget to restart your SSH daemon afterwards.
| ssh Connection refused, stuck at "debug1: Local version string" |
1,461,309,630,000 |
In my SSH config file, I have to enable the RequestTTY force for some important reasons. And currently my config file looks like this:
Host x.x.x.x
HostName yyyy
StrictHostKeyChecking no
RequestTTY force
IdentityFile ~/path/id_rsa
But now when I execute an scp command, it completes but creates an empty file on the destination path and below is the log that it generates:
debug2: channel 0: read<=0 rfd 4 len 0
debug2: channel 0: read failed
debug2: channel 0: close_read
debug2: channel 0: input open -> drain
debug2: channel 0: ibuf empty
debug2: channel 0: send eof
debug2: channel 0: input drain -> closed
debug2: channel 0: write failed
debug2: channel 0: close_write
debug2: channel 0: send eow
debug2: channel 0: output open -> closed
But if I comment out the RequestTTY force option in the config file, it executes properly and also copies the file properly.
Why does this behaviour occur?
Can anyone provide me with a workaround so that I won't have to disable the RequestTTY force option and also the file would be copied properly?
|
There are many possible solutions for that:
You can configure sudo not to require tty: RequireTTY in /etc/sudoers
You can force tty allocation on command-line in these specific cases, where you need it: ssh -tt host command
You can tell scp not to allocate TTY by -T or -o RequestTTY=no command-line option: scp -T file host:path/ or scp -o RequestTTY=no file host:path/
The reasons why does it happen are already explained. You spoil binary protocol by TTY control characters and vice versa.
| Why does SCP fail when "RequestTTY force" option is enabled? |
1,461,309,630,000 |
We are running CentOS 6.9 with OpenSSH_5.3p1 and created chrooted accounts for external users with the same home directory (mounted to htdocs). Problem is that the file .ssh/authorized_keys2 is owned by the first user (and this works already). How can I make it work for another user?
I tried to add an AuthorizedKeysFile in sshd_config with multiple file paths and I got the error garbage at end of line.
I tried to add an AuthorizedKeysFile in sshd_config in the match block of the second user and I got the error 'AuthorizedKeysFile' is not allowed within a Match block.
I cannot change the home directory because otherwise the path is different from the real path for development.
Any suggestions how to solve it?
May I have to upgrade OpenSSH to a newer version that supports multiple entries for AuthorizedKeysFile (I think I have to build it with rpm)? What about security updates afterwards?
|
One option is to use tokens to give each user a unique authorized_keys file.
From man sshd_config:
AuthorizedKeysFile
Specifies the file that contains the public keys that can be used
for user authentication. The format is described in the AUTHORIZED_KEYS FILE FORMAT section of sshd(8). AuthorizedKeysFile
may contain tokens of the form %T which are substituted during
connection setup. The following tokens are defined: %% is
replaced by a literal %, %h is replaced by the home directory
of the user being authenticated, and %u is replaced by the username of that user. After expansion, AuthorizedKeysFile is taken
to be an absolute path or one relative to the user's home directory. Multiple files may be listed, separated by whitespace.
Alternately this option may be set to none to skip checking
for user keys in files. The default is .ssh/authorized_keys .ssh/authorized_keys2.
Emphasis mine.
So you can set:
AuthorizedKeysFile .ssh/%u_authorized_keys
Then for user foo create an authorized_keys file .ssh/foo_authorized_keys.
A note on permissions
From man sshd:
~/.ssh/authorized_keys
...
If this file, the ~/.ssh directory, or the user's home directory
are writable by other users, then the file could be modified or
replaced by unauthorized users. In this case, sshd will not
allow it to be used unless the StrictModes option has been set to
no.
So you may need to stick your keys outside .ssh/, or else set StrictModes to no. If you set StrictModes to no make sure another user can't create an authorized_keys for someone else, or delete the other user's authorized keys. Probably best off doing something like:
AuthorizedKeysFile .ssh_%u/authorized_keys
Create a directory .ssh_foo/ for user foo, that only foo can read/write.
You can choose if you want to also allow .ssh/authorized_keys by using
AuthorizedKeysFile .ssh/authorized_keys .ssh_%u/authorized_keys
This will allow the "normal" form of authorized_keys to still work, and an authorized_keys file must be owned by your user and have correct permissions or it will be ignored. Still consider that it should not be possible to create an authorized_keys file for another user, which could just mean touching the file as root so it's empty.
| authorized_keys for multiple chrooted users with the same home directory |
1,461,309,630,000 |
Is there a command to extract information about the algorithm that is used (RSA, ECDSA, 3DES ...) for SSH keys, regardless of the format (pem, der etc)?
I looked into openssl, but I could not find anything about this.
|
You can use next command to get the type of the key (RSA, DSA, etc):
# ssh-keygen -l -f .ssh/id_rsa
2048 SHA256:4+Na0ttfBkspSFSYnRjwbwja8/b708lRxzqjPBzLJMw ........ (RSA)
# ssh-keygen -l -f .ssh/id_dsa
1024 SHA256:F6h53Zu0A9M094CbszkwxfQ5L2EZ0kUEpLkH0dp1alU ........ (DSA)
# ssh-keygen -l -f .ssh/id_ed25519
256 SHA256:b4mTk5rvo0SgazbzQxame6gX7r1MPtXeGNJY2q4Y3dg ........ (ED25519)
In the command you can specify file the private or the public key
| Extract ssh key algorithm |
1,461,309,630,000 |
I have SSH public key (generated on my Mac) in OpenSSH format like this:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXaDj1YGcvKIhUIgmjV/Mjz8so5O2tdxG9gVlTwCxuFLjcUOsciB5R+hZ28GZtb9tb0p4ZSGd8bLcUnI/tqFlVBfRKhfixbvJlDJkzh1eqzqjgCz7Sgd7vo/9pX4FNmajcdt4nsgMI0Q0NLZOWF0M90gTAkcpfCVyt561IIrHK0MpWPqQbp917X8hfRH23sgo8B471FhN6j3ghS18OcAG8LSzCQ5IjJzyqzRRYLpYVdGVyrqNKV0wBOP7dzmZAcpit4XCtRIESKdQGzPCMcctgh2doBPwFyP1AUcTCrq5skZgik6RjaJAlCm3rxPs0bJDGInWEg0lTnTc7hEmV4tf3 nameofthekey
And I need to convert to PKCS#1 in HEX with this formatting:
30818602 8180E6B0 25E45C19 54F3DBAD D41C79BF 2054F2C9
33775177 6F60F3B0 9654B03D 02A6A30F B04A5D59 E9BA7846
32059FB6 1157F39B 2C60C890 9B92EFA6 CD566AE2 41621AEB
7BC30538 7065BD5A E3D2380E F1ABF4BF A8EFB0C9 E9BB06E0
8A060E0E 2022047C 009BA3F6 47257E1B B3498941 3C1281BA
C5D64786 377B7426 2B5AA315 41C70201 25
and put in in my Huawei OLT terminal for SSH RSA key access.
Thank you.
|
I spent one night and I found this solution:
OpenSSH public key must be converted to PKCS#1 PEM-encoded public key that is in base64:
ssh-keygen -f id_rsa.pub -e -m pem
Next, use base64 to HEX converter like this: http://tomeko.net/online_tools/base64.php?lang=en
Enter string without begin and end mark
-----BEGIN RSA PUBLIC KEY-----
-----END RSA PUBLIC KEY-----
to converter and click convert
For example:
You enter this into converter:
MIIBCgKCAQEA12g49WBnLyiIVCIJo1fzI8/LKOTtrXcRvYFZU8AsbhS43FDrHIgeUfh2dvBmbW/bW9KeGUhnfGy3FJyP7ahZVQX0SoX4sW7yZQyZM4dXqs6o4As+0oHe76P/aV+BTZmo3HbeJ7IDCNENDS2TMhdDPdIEwJHKXwlcreetSCKxytDKVj6kG6fde1/IX0R9t7IKPAeO9RYTeo94IUtfDnABvC0swkxSIyc8qs0UWC6WFXRlcq6jSldMATj+3c5mQHKYreFwrUSBEinUBszwjHHLYIdnaAT8Bcj9QFHEwS6ubJGYIpOkY2iQJQpt68T7NGyQxiJ1hIGJU503O4RJleLV9wIDAQAB
And you get this:
3082010A0282010100D76838F560672F2888542209A357F323CFCB28E4EDAD7711BD815953C02C6E14B8DC50EB1C881E51F87676F0666D6FDB5BD29E1948677C6CB7149C8FEDA8595505F45F85F8B16EF2650C99338757AACEA8E00B3ED281DEEFA3FF695F814D99A8DC76DE27B20308D12D0D2D939617433DD204C091CA5F095CADE7AD4822B1CAE0CA563EA41BA7DD7B5FC85F447DB7B20A3C078EF516137A8F78214B5F0E7001BC2D2CC2439223273CAACD14582E9615746572AEA34A574C0138FEDDCE66407298ADE170AD44811229D406CCF08C71CB6087676804FC05C8FD4051C4C2AEAE6C91982293A4636890250A6DEBC4FB346C90C62275848349539D373B844978E2D7F70203010001
For network equipment like Huawei GPON OLT or switches or Juniper you must little edit output to groups of 8 characters in 6 colnums like this: (via text editor add classic spaces and line breaks)
3082010A 02820101 00D76838 F560672F 28885422 09A357F3
23CFCB28 E4EDAD77 11BD8159 53C02C6E 14B8DC50 EB1C881E
51F87676 F0666D6F DB5BD29E 1948677C 6CB7149C 8FEDA859
5505F44A 85F8B36E F2650C99 338757AA CEA8E00B 3ED281DF
EFA3FF69 5F814D99 A8DC76DE 27B20308 D10D0D2D 93961743
3DD204C0 91CA5F09 5CADE7AD 4822B1CA D0CA563E B41BA7DD
7B5FC85F 447DB7B2 0A3C078E F516137A 8F78214B 5F0E7001
BC2D2CC2 43922327 3CAACD14 582E9615 746572AE A34A574C
0138FEDD CE664072 98FAE170 AD448112 29D416CC F08C71CB
60876768 04FC05C8 FD4051C4 C2AEAE6C 91982293 A4636890
250A6DEB C4FB346C 90C62275 84834953 9D373B84 4995E2D7
F7020301 0001
Now you can put this RSA public key in to console, save, assign RSA key to user and you can now login with your SSH private key.
| Convert OpenSSH public key to a PKCS#1 in HEX format with spaces and columns |
1,461,309,630,000 |
I have installed openssh server. I want to disable banner which is shown when I do ::
nc 0.0.0.0 22
It shows something like this :: SSH-2.0-OpenSSH_6.7p1 Raspbian-5 .
How to make it show something else or nothing at all ?
|
This banner
SSH-2.0-OpenSSH_6.7p1 Raspbian-5
is part of SSH protocol as described in chapter
4.2. Protocol Version Exchange
of RFC 4253:
When the connection has been established, both sides MUST send an
identification string. This identification string MUST be
SSH-protoversion-softwareversion SP comments CR LF
You can't get rid of the SSH-2.0 part. The softwareversion part is used commonly for interoperability and it is also not good idea to remove it. The comments are optional and don't need to be there (but Debian puts them in by default).
You can get rid of the comment using DebianBanner option in sshd_config. Setting it to no and restarting ssh server will not show it any more.
| Change SSH banner which is grabbed by netcat |
1,461,309,630,000 |
My office has one default gateway and behind that is a local network with locally assigned IP addresses to all computers including mine.
I hold admin in my Ubuntu installed office PC and is it essential that I access the computer during weekends through SSH.
At office, I do not have a public IP but I always get the same local IP from the DHCP. I'm free to set up any software I like in my pc although I cannot set up port forwarding in the main firewall.
I get a public IP to my home computer which also runs Linux. please note I cannot install Team Viewer-like software.
How can I solve my problem?
|
It's easy:
[execute from office machine] Setup connection Office -> Home (as Home has public IP). This will setup reverse tunnel from your office machine to home.
ssh -CNR 19999:localhost:22 homeuser@home
[execute from home machine] Connect to your office from home. This will use tunnel from the step 1.
ssh -p 19999 officeuser@home
Please ensure, that ssh tunneling is not against your company policies, cause sometimes you can get fired for such connection schema (e.g. my employer will fire me for that).
ps. In the first step you may want to use autossh or something like that, so your tunnel connection will be automatically restored in case of unstable network.
| SSH PC at office in local network from home |
1,461,309,630,000 |
I have the reverse problem that most people seem to be having. If I start an X application while logged into ssh, it displays on the server(host) machine instead of the client(local). This is the command I use
$ ssh -X -p 6623 [email protected]
My $DISPLAY variable appears correct on the client.
$ echo $DISPLAY
:0
I want X applications from the server to display locally on the client (the machine I'm physically at). I don't know what is causing this.
|
For the sake of this conversation lets say there are 2 machines named lappy and remotey. The lappy system is where you'd be running your ssh commands from. The system you're connecting to is remotey.
1. Display GUIs from remotey on lappy
lappy .-,( ),-.
__ _ .-( )-. remotey
[__]|=| ---->( network )------> ____ __
/::/|_| '-( ).-' | | |==|
'-.( ).-' |____| | |
/::::/ |__|
NOTE: on lappy, `ssh` to remotey, run GUI, see GUI on lappy
Your shell's configuration files are likely setting the environment variable DISPLAY=:0. You can grep for this like so:
$ grep DISPLAY $HOME/{.bash*,.profile*}
If that doesn't return anything back then the system you're logging into is probably the culprit. Take a peek in this directory as well.
$ grep DISPLAY /etc/profile.d/* /etc/bash*
If you'd rather just leave this be you can override this behavior by instructing ssh to redirect X traffic back to your client system, like so:
$ ssh -X user@remoteserver
Example
Here I have a remote server that has $DISPLAY getting set to :0 similar to yours.
$ ssh -X skinner "echo $DISPLAY"
:0
But no matter, I can still invoke X applications and have them remote displayed to my system that's doing the ssh commands. I don't even have to login, I can simply run GUI's directly like so:
$ ssh -X skinner xeyes
As a bonus tip you'll probably want to change which ciphers are being used, to help improve the performance of your X11 traffic as it passes over your SSH tunnel.
$ ssh -c arcfour,blowfish-cbc -X skinner xeyes
2. Displaying GUIs on remotey
lappy .-,( ),-.
__ _ .-( )-. remotey
[__]|=| ---->( network )------> ____ __
/::/|_| '-( ).-' | | |==|
'-.( ).-' |____| | |
/::::/ |__|
NOTE: on lappy, `ssh` to remotey, run GUI, see GUI on remotey
If you're SSH'ing into remotey from lappy but would like to keep the GUIs from being displayed on lappy, then simply drop the -X switch from your ssh invoke.
$ ssh -p 6623 [email protected]
3. Eliminating $HOME/.ssh/config
Often times a user's $HOME/.ssh directory can introduce unknowns as to what's going on. You can temporarily silence the use of the config file in this directory like so when performing tests.
$ ssh -F /dev/null -p 6623 [email protected]
4. Eliminating remote shell's configs
You can use the following test to temporarily disable the shell's configuration files on remotey like so:
$ ssh -t -X -p 6623 [email protected] "bash --norc --noprofile"
With the above, none of the setup should be getting sourced into this Bash shell, so you should be able to either set DISPLAY=:0 and then display GUIs to remotey's desktop.
You can use the following trick to help isolate the issue, by first removing --noprofile and trying this command:
$ ssh -t -X -p 6623 [email protected] "bash --norc"
Then followed by this command:
$ ssh -t -X -p 6623 [email protected] "bash --noprofile"
The first version will tell you if the problem lies in your /etc/bashrc & $HOME/.bashrc chain of configuration files, while the second version will tell you if the problem lies in the $HOME/.bash_profile configuration file.
| SSH - How to make X applications run on client? |
1,461,309,630,000 |
I configured key pairs for SSH connection.
It works but of course asks for the passphrase.
ssh [email protected]
So now I try to login with sshpass which I have installed. I tried with -p property but also and with -f property and nothing works - it just hangs.
verbose gives these info on the client side
sshpass -v -p "pass" ssh [email protected]
SSHPASS searching for password prompt using match "assword"
SSHPASS read:
SSHPASS read: Enter passphrase for key '/home/user1/.ssh/id_rsa':
On the server side I can see these information in the log:
Accepted key RSA SHA256:V/V29pA2Ps5k/lBgz2R5XFP6vaaaOUN5hj0hca+j8TI found at __PROGRAMDATA__/ssh/administrators_authoriz
ed_keys:1
debug3: mm_answer_keyallowed: publickey authentication test: RSA key is allowed
debug3: mm_request_send: entering, type 23
debug3: send packet: type 60 [preauth]
debug2: userauth_pubkey: authenticated 0 pkalg rsa-sha2-256 [preauth]
debug3: user_specific_delay: user specific delay 0.000ms [preauth]
debug3: ensure_minimum_time_since: elapsed 19.018ms, delaying 1.849ms (requested 5.217ms) [preauth]
Postponed publickey for user1 from 10.7.141.243 port 44750 ssh2 [preauth]
Thanks a lot for your kind assistance!
|
ssh prompts for and reads password (or passphrase) using the terminal (/dev/tty), not its stdin. This way you can pipe/redirect data to/from ssh and still be able to provide a password when asked. But to provide a password not via the terminal, one needs to present a "fake" terminal to ssh. This is what sshpass does.
When you sshpass … ssh …, sshpass runs ssh in a dedicated emulated terminal. This means ssh does not read directly from your terminal, sshpass does. And ssh does not print directly to your terminal, sshpass does. Eventually sshpass will act as a relay, so it will be as if ssh used your terminal. But before this happens, sshpass intercepts what ssh prints; it also injects the string you specify after -p, then ssh "sees" the string as coming from the terminal ssh is using (which is not your terminal). This way ssh can be fooled you typed the password, when it's sshpass who "typed".
By default sshpass waits for assword: (or assword1?) to appear as a part of the prompt for password. E.g. if you didn't use a key and you didn't use sshpass, ssh would print:
[email protected]'s password:
and it would wait for you to type your password. If you used sshpass to provide your password, then sshpass would intercept this message and "type" the password for you. By waiting for the right prompt sshpass knows when ssh expects a password, only then it passes your password.
In your case the prompt was different. ssh did not ask for the password, it asked for the passphrase using a different prompt. The prompt from ssh was exactly Enter passphrase for key '/home/user1/.ssh/id_rsa':, there was nothing matching assword:, so sshpass kept waiting for the default prompt that never came.
Use -P to override the default.
-P
Set the password prompt. Sshpass searched for this prompt in the program's output to the TTY as an indication when to send the password. By default sshpass looks for the string assword: (which matches both Password: and password:). If your client's prompt does not fall under either of these, you can override the default with this option.
(source: man 1 sshpass)
In your case it may be:
sshpass -P assphrase -p "pass" ssh [email protected]
Now if sshpass intercepts Enter passphrase … coming from the ssh, it will respond with whatever you specified after -p. Next it will sit as a relay between your terminal and the one ssh is using; it will become transparent.
In general sshpass can be used to provide a password (a string in general) to any tool that normally uses the terminal (as opposed to stdin+stdout+stderr) to prompt for and read the password. -P allows you to adjust the command to the prompt the tool uses.
1 The manual says assword:, but the output from your sshpass -v says using match "assword". One way or another you need -P to properly pass a passphrase.
| "ssh" works but "sshpass" doesn't - how is this possible? |
1,461,309,630,000 |
How are lines removed from a standard (system) systemd unit file? Here are the details:
ls -la /etc/ssh/ssh_host_*key*
This shows I have unused and unwanted host key types. They are not configured in my sshd_config, but I prefer they not exist at all. If I remove them, they get auto-regenerated.
From what I see, /usr/lib/systemd/system/sshd.service includes:
Wants=sshdgenkeys.service
The contents of that are shown below with cat /usr/lib/systemd/system/sshdgenkeys.service:
[Unit]
Description=SSH Key Generation
ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key
ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key.pub
ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key
ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key.pub
ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key
ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key.pub
ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key
ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key.pub
[Service]
ExecStart=/usr/bin/ssh-keygen -A
Type=oneshot
RemainAfterExit=yes
I know I can override or create a unit file setting using systemctl edit, but how are lines like ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key removed?
What I want to end up with is similar to this:
[Unit]
Description=SSH Key Generation
ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key
ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key.pub
ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key
ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key.pub
[Service]
ExecStart=/usr/bin/ssh-keygen -t rsa|ed25519 -a 32
Type=oneshot
RemainAfterExit=yes
I'm not sure that command is correct for ssh-keygen, but that's the general idea. I only want to generate two host key types, not all.
|
In systemd units, lists can typically be reset in overrides by assigning an empty value. This works for conditions too:
If any of these options is assigned the empty string, the list of conditions is reset completely, all previous condition settings (of any kind) will have no effect.
In your override, use this:
ConditionPathExists=
ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key
ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key.pub
ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key
ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key.pub
| How to remove (not override, not create new) options from systemd unit files? |
1,461,309,630,000 |
I have already configured login to ssh with keys and it works fine. The problem is that when I'm connecting to the server with key and included password but I don't see any failed login attempts when I type a wrong password. There are no failed login attempts using key in:
/var/log/audit/audit.log
or
/var/log/secure
Other words i can type password to key til i die without any action.
Do you have any ideas how to log to file failed login attemps to ssh using key with password ?
OS is : Red Hat Enterprise Linux Server release 7.3 (Maipo)
Thank you in advance.
This is log from the server when i have typed many times wrong password:
Connection from my_ip port 51115 on server_ip port 22
sshd[3639]: Found matching RSA key: 00:12:23 ...
sshd[3639]: Postponed publickey for some_user from ip_address port 51115 ssh2 [preauth]
|
It sounds like you've configured your client key to require a password to open the key before connecting to the server. It won't be logged by your server because that occurs on the client machine.
| Logging wrong password for ssh with key |
1,461,309,630,000 |
Say for some reason, there is only a "user" account on a shhd server. Everyone has his own private key to ssh to the server, as "user".
Then, is there a way to see who is he (during or after his session)?
|
You can see which SSH public key was used in the syslog.
The authentication subset of the syslog is usually at /var/log/auth.log. For the whole syslog, you can try /var/log/syslog or /var/log/messages.
The log lines should look something like this:
Sep 10 19:17:00 server.example.com sshd[1337]: Accepted publickey for ansible from 127.0.0.1 port 59934 ssh2: RSA 5a:5d:18:5d:21:b4:e3:f3:8a:ec:c3:d6:93:99:87:ae
You should be able to parse this log with a tool like logstash to build real statistics.
| How to know which public key was used when someone used passwordless ssh login? |
1,461,309,630,000 |
Let's say I use this command:
ssh -vvv user@server
I get an output similar to this:
send packet: type 21
ssh_set_newkeys: mode 1
receive packet: type 6
SSH2_MSG_SERVICE_ACCEPT received
receive packet: type 51
Permission denied (publickey,password)
What are all these packet-types?
Where can I read and learn about them? I always google something like ssh packet type51, but there must be a place where all the types are listed
If you know how to understand this ssh verbose mode, where did you learn this?
Thanks for your help :)
|
SSH is defined in IETF RFCs like
RFC4253 - The Secure Shell (SSH) Transport Layer Protocol (note
that there's errata and several updates)
RFC4250 - The Secure Shell (SSH) Protocol Assigned Numbers
In general the places to find out how things work are IEEE standards and IETF RFCs. They're not the easiest read, the language takes a bit of getting used to.
To find resources of learning how to use/understand SSH you can search the internet. There's a multitude of websites for this. You can also buy a book from publishers like O'Reilly - those tend to be thick, but are also very comprehensive.
That gives you the theoretical background. In the end you gain practical knowledge only in practical situations. I.e. you learn how to interpret SSH logs by analyzing SSH logs :-)
See also IANA "SSH Parameters" -page with direct links to the applicable RFCs.
Techtarget's 5-part SSH tutorial
NOTE: These links are applicable for SSH-2, accepted as standard 2006. It's a complete re-write, and incompatible with original SSH-1, which was published 1996 and not much in use nowadays.
| How to read and debug SSH verbose-mode? |
1,461,309,630,000 |
Short Description
I have been seeing an strange behaviour on my SSH connection for years but never thought of raising a question until today. I tried to search a lot about this but couldn't find any reason.
Environment
Basically, I have various AWS EC2 instances running on different regions (like Ireland, Mumbai etc.).
I have a Mac.
And I'm located in India (in case it strikes someone some reason).
Problem Statement 1
When my Mac is connected to a personal hotspot (from a Samsung device or from an iPhone) over 4G network, my SSH connection freezes after a few minutes (not more than 3) if I do not work on the SSH session (basically, the SSH connection went ideal). So I have to keep pressing the arrow key just to keep it alive.
Problem Statement 2 (which is not a problem)
But when my Mac is connected to a Wifi broadband connection, this problem never occurs. My SSH connection stays connected for hours even after I wake up my Mac from sleep (open the lid).
Based on my Googling again today, I found various articles which gives solution to use options like TCPKeepAlive or ServerAliveInterval:
What options `ServerAliveInterval` and `ClientAliveInterval` in sshd_config exactly do?
How does tcp-keepalive work in ssh?
https://raspberrypi.stackexchange.com/questions/8311/ssh-connection-timeout-when-connecting
https://patrickmn.com/aside/how-to-keep-alive-ssh-sessions/
But I couldn't find any post which dictates this problem. Does anyone of you have any idea about this behaviour? I'll be happy to provide you any possible details of my 4G hotspot connection.
|
I would surmise that a system tracking (and forgetting) connections statefully is causing this. When NAT is in use (and it's very often the case when not on IPv6) then usually the system doing NAT needs a memory to remember where to send back replies. For your Wifi broadband, the system doing NAT might have a longer memory to remember active connections (for example, Linux netfilter's conntrack by default remembers TCP connections for 5 days, while it remembers UDP flows for 2 or 3 minutes). The equivalent system doing NAT on your 4G path has probably a shorter memory, a bit less than 3mn.
To work around this, as you found and linked in your question, you can set the specific ssh parameter ServerAliveInterval that will send empty data (as SSH protocol) periodically when there's no activity in a way similar to TCP KeepAlive. This will make the connection always seen as active for the system doing NAT, and it won't forget it. So in your ~/.ssh/config file you could add:
ServerAliveInterval 115
with 115 a value chosen to be slightly less than 2mn to stay conservative: a value inferior to the estimated tracking duration of active connections on the invisible NAT device in the path, but not too low either (see later). So that at worse, when the tracking state is 5s from being about to be deleted, it gets back to the supposed 120s lifespan.
The drawback is that (on your Wifi broadband access anyway) if you lose connectivity for some time and then recover it, this might have made the client think the remote server was down and it will have closed the connection. You can also tweak ServerAliveCountMax for this, but anyway if the default value is 3, that would require something like 3*115=345s of connectivity loss, more than 5mn, before having a chance to have this problem.
The server side has an equivalent ClientAliveInterval that you can set there in its sshd_config file instead, for the same purpose. This would have the added benefit of not keeping around ghost ssh client connections seen as still connected for some length of time when the client side anyway lost connectivity.
| SSH connection freezes on 4G Hotspot but not on any Wifi |
1,461,309,630,000 |
In sshd config you can specify the option TCPKeepAlive yes. These Pakets are not encrypted so the could be spoofed.
With the options
ClientAliveInterval
ClientAliveCountMax
ServerAliveInterval
ServerAliveCountMax
you can specify the interval of the keep alive packets and the timeout (*CountMax) after which the connection is dropped. See also here What options `ServerAliveInterval` and `ClientAliveInterval` in sshd_config exactly do?
With TCPKeepAlive you can only enable it.
So what is the interval for the TCP-Pakets beeing sent?
After how many unsuccessful packets the connection is regarded broken and closed? Since default values are:
#TCPKeepAlive yes
#ClientAliveInterval 0
#ClientAliveCountMax 3
As far as I understand: The detection and closing of broken/inactive connections solely depends on the TCPKeepAlive option in the default configuration. So it is quite important to know that values.
|
The reason why OpenSSH doesn't offer any tweaks for TCPKeepAlive (which is implemented by the OS) is probably because there's no portable way to change its parameters; the only portable thing is turning it on or off with setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on_off).
On Linux, you can see (and change) the default values via the /proc filesystem, as documented in the tcp(7) manpage:
grep -T . /proc/sys/net/ipv4/tcp_keepalive*
/proc/sys/net/ipv4/tcp_keepalive_intvl: 75
/proc/sys/net/ipv4/tcp_keepalive_probes: 9
/proc/sys/net/ipv4/tcp_keepalive_time: 7200
So, it will wait 2 hours until it will consider a connection idle, and then send 9 probes at the interval of 75 seconds.
On Linux, FreeBSD and NetBSD (but not on OpenBSD) you can also change those options on a per-socket basis with
setsockopt(fd, IPPROTO_TCP, TCP_KEEP{CNT,IDLE,INTVL}, &val)
but, as mentioned, OpenSSH doesn't do that.
| OpenSSH: What is the interval for TCPKeepAlive option? |
1,461,309,630,000 |
I'd like to run a privileged command upon successful SSH logins at the server's end. However, this has to be in the server configuration (sshd_config or anything else that cannot be manipulated or circumvented by the user) as I need this to be mandatory. That is, however restricted the system account used is, it needs to be able to manipulate a piece of data that requires superuser privileges (namely use ipset add conditionally - which I can script). Oh and I'd like to be able to access the contents of SSH_CLIENT, please - despite privileged execution. The command also must be unaffected by ChrootDirectory.
I am aware of /etc/ssh/sshrc, but that appears to be "client-side", i.e. it's being run by the user who is logging into the machine.
Does such a facility exist in OpenSSH? I am using version 6.6.
Also, the man page (ssh(1)) isn't all too clear about sshrc:
/etc/ssh/sshrc
Commands in this file are executed by ssh when the user logs in, just before the user's
shell (or command) is started. See the sshd(8) manual page for more information.
So does this mean it also runs whenever external commands (via ForceCommand) or subsystems like internal-sftp get invoked, despite restricting settings like PTY allocation or forcing a chroot? If so, I could resort to a restrictive /etc/sudoers entry if there is no other way at all.
NB: I am not using inetd for obvious reasons (see sshd(8)) as described here.
|
You can do this using PAM and the pam_exec.so module.
You simply add a line to /etc/pam.d/sshd to the 'session' section such as the following:
session optional pam_exec.so /usr/local/bin/ipset-ssh
Where ipset-ssh is some script you create.
The script will be run as root. You can get the client's IP address with the PAM_RHOST variable. You'll also want to check the PAM_TYPE variable as your script will be executed both on login, and logout. On login PAM_TYPE will be set to open_session. On logout it's set to close_session.
Here is the complete list of variables that I get from a simple test (I put env > /tmp/pamenv in script):
PAM_SERVICE=sshd
PAM_RHOST=127.0.0.1
GNOME_KEYRING_CONTROL=/home/phemmer/.cache/keyring-vJUUda
PAM_USER=phemmer
PWD=/
GNOME_KEYRING_PID=19742
SHLVL=1
PAM_TYPE=open_session
PAM_TTY=ssh
_=/usr/bin/env
Your script could be as simple as:
#!/bin/bash
[[ "$PAM_TYPE" == "open_session" ]] && ipset add whitelist $PAM_RHOST
| Is there a way to run a privileged command upon successful SSH login (not necessarily with shell or PTY)? |
1,461,309,630,000 |
I have a problem with an SSH session freezing after using it again when it was idle for a while.
The problem is that the session doesn't freeze immediately, I can still use it. But as soon as a command sends more data, it freezes before any output arrives, and I have to restart the terminal.
If have read earlier solutions about MTU, but there, the session freezes everytime. Here it only happens after a period of inactivity.
Note that I have set ServerAliveInterval 120 in .ssh/ssh_config
Any clues about how I can solve this?
|
Change ~/.ssh/ssh_config to ~/.ssh/config. Make sure the permissions on it are 700.
This discussion has a lot of good information. You can also follow the tag for ssh (just click on /ssh under your question) to go to a tag wiki for more information and trouble shooting guidance.
| SSH connection freezes after bigger output when inactive for a while |
1,461,309,630,000 |
I'm trying to set up SSH multiplexing, but I'm running into an error, and there are insofar 0 hits on Google for the exact error message.
I created ~/.ssh/config with the contents:
Host *
ControlPath ~/.ssh/master-%r@%h:%p
Then, I created the master connection by running:
ssh -vMM [email protected]
which seems to create the multiplexing socket successfully:
...
Authenticated to host.example.com ([1.2.3.4]:22).
debug1: setting up multiplex master socket
debug1: channel 0: new [/home/user/.ssh/[email protected]:22]
debug1: channel 1: new [client-session]
debug1: Entering interactive session.
...
Then, I try running a command via ssh in another window:
ssh -v [email protected] ls
However, this seems to fail to use the multiplexing socket:
OpenSSH_7.5p1, OpenSSL 1.1.0f 25 May 2017
debug1: Reading configuration data /home/user/.ssh/config
debug1: /home/user/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
Master refused session request: Permission denied
debug1: Connecting to host.example.com [1.2.3.4] port 22.
...
What could cause the Master refused session request: Permission denied error to occur?
Edit: The permissions of ~/.ssh and ~/.ssh/config are 700 and 644 respectively, so I don't see an issue there. ~/.ssh/master-* doesn't exist, I guess it's an abstract UNIX socket (and thus does not actually exist in the filesystem)? But then, that still doesn't explain the "access denied" error.
Also, I noticed that when attempting to establish the second connection, the master connection prints:
debug1: channel 2: new [mux-control]
debug1: permanently_drop_suid: 0
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
debug1: channel 2: free: mux-control, nchannels 3
Perhaps this is related. I'm connected using an unencrypted SSH key, so I don't see why SSH would need to ask for a password.
|
I've figured out what is causing the "Access denied" error.
By default, SSH seems to want to interactively ask for permission when another SSH process wants to use an existing multiplex session. However, the ssh-askpass program, which it uses to ask for permission, was missing on my system, so SSH defaults to "no, don't grant access", thus resulting in an "access denied" error message on the client.
If ssh-askpass is installed (which is in the x11-ssh-askpass package on Arch Linux), then a dialog such as the following will be displayed:
Selecting "OK" will allow the connection attempt to continue.
The prompt itself was caused because I specified -M twice on the master's command line. To quote SSH(1):
Multiple -M options places ssh into “master” mode with confirmation required before slave connections are accepted.
| Master refused session request: Permission denied |
1,461,309,630,000 |
Is there any way to configure OpenSSH (/etc/ssh/sshd_config) server to allow private keys necessarily with passphrase?
|
No, you have little control over how the private keys are configured, and you can't detect / enforce any passphrase requirement on them.
You also can't limit the size of the keys without modifying the OpenSSH source itself (i.e. there is no configuration option to achieve a minimum key length limit).
You can limit the type of public keys accepted using the PubkeyAcceptedKeyTypes parameter, but not the length.
PubkeyAcceptedKeyTypes
Specifies the key types that will be accepted for public key
authentication as a comma-separated pattern list. Alternately if
the specified value begins with a `+' character, then the specified key
types will be appended to the default set instead of
replacing them. The default for this option is:
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,
ecdsa-sha2-nistp521,ssh-ed25519,
ssh-rsa,ssh-dss
| How to limit connections to OpenSSH server to using private keys necessarily with passphrase? |
1,461,309,630,000 |
By default, recent versions of OpenSSH automatically set ForwardX11Timeout to 20 minutes if you set ForwardX11Trusted to no.
This means that 20 minutes after you start your ssh connection, you can't open any more X clients, because the authentication token has expired. Especially bad if you try to use this with long-lived connections and ControlMaster.
I've tried disabling by setting to 0 (does not work, causes instant expiration) and by setting to a really long value (do not do this, it will crash your X server. Limit is somewhere between 3 and 4 weeks).
How can I completely disable the timeout?
|
There was a patch 2018-04 and discussion 2018-06 but my search of mailing list archive by subject lines alone suggests it was not yet accepted as of 2019-04.
Duplicating some related info I posted at https://superuser.com/a/1429080/1027014 just now -
The maximum timeout is uint_max of milliseconds minus some slack, just over 24 days. OpenSSH_7.4p1 will accept ssh -o ForwardX11Timeout=2147423s -X ... which is the best answer I can make now. ForwardX11Timeout above this may crash the XServer in some version combinations.
On MacOS with XQuartz, I have seen Warning: untrusted X11 forwarding setup failed: xauth key data not generated and upon digging further, /opt/X11/bin/xauth: timeout in locking authority file /var/folders/..../xauthfile .
| Disable ForwardX11Timeout without ForwardX11Trusted in OpenSSH Client? |
1,461,309,630,000 |
We have a server on the company network named serverA, and if I type ssh serverA, it will connect my PC to this server, even though there is no entry for this server in my /etc/hosts, but I used to have another PC where I do have to set this up manually in /etc/hosts. So, how does ssh discover hostnames on the network, and how can I make sure it works? (Both these machines I mentioned are running Kubuntu Linux, the older one runs 12.10, the newer one runs 13.04.)
I have the following content in /etc/resolv.conf:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search mycompany.com
Processes listening on port 53:
sudo ss -ulnp | grep 53
#UNCONN 0 0 *:5353 *:* users:(("avahi-daemon",937,12))
#UNCONN 0 0 127.0.1.1:53 *:* users:(("dnsmasq",1781,4))
#UNCONN 0 0 :::5353 :::* users:(("avahi-daemon",937,13))
|
This happens when the server is within the DNS search domain you have configured.
For example, my current search domain is example.com:
$ grep ^search /etc/resolv.conf
search example.com
I can now do the following transparently:
$ ping foo.example.com
PING foo.example.com (127.0.0.1) 56(84) bytes of data.
^C
$ ping foo
PING foo.example.com (127.0.0.1) 56(84) bytes of data.
^C
Search domains allow automatic translation between the machine's name and the fully qualified domain name (FQDN).
| how does ssh discover hostnames on the network? |
1,461,309,630,000 |
I am able to ping my friend but not able to do ssh. Why so? He is using a modem. I thought there might be some firewall enabled. I told him to type
#iptables -F
He did that, but still I am not able to do ssh on his system. How can I do this?
I get the error: ssh: connect to host 182.64.31.131 port 22: Connection refused
RESULT OF ifconfig on his system
inet addr:127.0.0.1 Mask:255.0.0.0
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
He told me his dynamic ip by using whatismyip.com
I tried ssh on that ip.
PS: sshd service is running on his system.
I tried nmap and came to know that port 22 is not opened.
|
As @sbtkd85 notes, it's almost certainly because port forwarding needs to be set up at his router/access point.
Here's some related/maybe pertinent info:
http://forum.portforward.com/YaBB.cgi?num=1139203841
Cheers,
Robert
| Can ping but can't do ssh |
1,461,309,630,000 |
Here are basics information:
$ which ssh
/opt/local/bin/ssh
It's like that because I'm using MacPorts and it did install there.
I did the sudo port load openssh
When doing a netstat -an | grep LISTEN on reboot. I have this:
tcp4 0 0 *.2222 *.* LISTEN
tcp6 0 0 *.2222 *.* LISTEN
tcp46 0 0 *.5900 *.* LISTEN
tcp4 0 0 *.88 *.* LISTEN
tcp6 0 0 *.88 *.* LISTEN
tcp4 0 0 *.631 *.* LISTEN
tcp6 0 0 *.631 *.* LISTEN
tcp4 0 0 *.22 *.* LISTEN
tcp6 0 0 *.22 *.* LISTEN
tcp4 0 0 *.139 *.* LISTEN
tcp4 0 0 *.445 *.* LISTEN
tcp4 0 0 *.548 *.* LISTEN
tcp6 0 0 *.548 *.* LISTEN
tcp4 0 0 127.0.0.1.631 *.* LISTEN
tcp6 0 0 ::1.631 *.* LISTEN
then here are the results of nmap:
[email protected] ~ nmap -p 22 localhost 0 --15:23--
Starting Nmap 5.50 ( http://nmap.org ) at 2011-02-10 15:24 CET
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000083s latency).
PORT STATE SERVICE
22/tcp open ssh
Nmap done: 1 IP address (1 host up) scanned in 0.19 seconds
[email protected] ~ nmap -p 2222 localhost 0 --15:24--
Starting Nmap 5.50 ( http://nmap.org ) at 2011-02-10 15:25 CET
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000072s latency).
PORT STATE SERVICE
2222/tcp open EtherNet/IP-1
Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds
Now what happen when I try to ssh on localhost
[email protected] ~ ssh localhost 0 --15:30--
Connection closed by 127.0.0.1
When specifying the 2222 port.
[email protected] ~ ssh localhost -p 2222 255 --15:31--
Last login: Thu Feb 10 15:18:00 2011 from localhost
Succeed! The reason: I found it in the sshd_config file on the /opt/local/etc/ location. port 2222 here the file:
[email protected] ~ cat /opt/local/etc/ssh/sshd_config | less 0 --15:29--
# $OpenBSD: sshd_config,v 1.81 2009/10/08 14:03:41 markus Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
Port 2222
So I decided to change the port in that file to 22
relaunch the service with unload/load as follow:
[email protected] /opt/local/etc/ssh ssh localhost -p 2222 0 --15:35--
Last login: Thu Feb 10 15:32:15 2011 from localhost
[email protected] ~ sudo port unload openssh 0 --15:35--
[email protected] ~ sudo port load openssh 0 --15:36--
[email protected] ~ ssh localhost -p 2222 0 --15:36--
ssh: connect to host localhost port 2222: Connection refused
Well, I'm feeling lucky and I try ssh localhost
[email protected] ~ ssh localhost 255 --15:36--
Connection closed by 127.0.0.1
No such a thing as luck I suppose. Here is a -vv of the command:
[email protected] ~ ssh -vv localhost 255 --15:37--
OpenSSH_5.6p1, OpenSSL 1.0.0c 2 Dec 2010
debug1: Reading configuration data /opt/local/etc/ssh/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug2: key_type_from_name: unknown key type '-----END'
debug1: identity file /Users/pierre/.ssh/id_rsa type 1
debug1: identity file /Users/pierre/.ssh/id_rsa-cert type -1
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug2: key_type_from_name: unknown key type '-----END'
debug1: identity file /Users/pierre/.ssh/id_dsa type 2
debug1: identity file /Users/pierre/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 1.99, remote software version OpenSSH_5.2
debug1: match: OpenSSH_5.2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.6
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 127/256
debug2: bits set: 520/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'localhost' is known and matches the RSA host key.
debug1: Found key in /Users/pierre/.ssh/known_hosts:1
debug2: bits set: 534/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /Users/pierre/.ssh/id_rsa (0x10030e540)
debug2: key: /Users/pierre/.ssh/id_dsa (0x10031dcf0)
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/pierre/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
Connection closed by 127.0.0.1
What do you think?
|
OS X comes with sshd already. It's running if you enable "Remote Login" in System Preferences under Sharing.
If all you want to do is make it listen on a non-default port, the trick is as follows:
Open /System/Library/LaunchDaemons/ssh.plist in your favorite text editor.
Find the SockServiceName key.
Change the string value to something like ssh-alt, then save the plist file.
Add an entry for ssh-alt to the /etc/services file.
Go into the Sharing preference pane and toggle the "Remote Login" checkbox off and back on. You'll find that the native sshd is now listening on the other port.
You'd think you could avoid all that by editing /etc/sshd_config, but you'd be wrong. The native sshd pays attention to the plist file, only.
| I can't ssh on localhost at a certain port on os x |
1,461,309,630,000 |
I have ArchLinux (kernel 4.8.4-1) machine which I try to turn into SSH server. For the last few days I've been struggling with getting it to work. I have read loads of articles, tutorials and other stuff like this but all of them look the same and none solves my problem.
After running
$ssh -vvv alagris@Oelkozadam
I get:
OpenSSH_7.3p1, OpenSSL 1.0.2j 26 Sep 2016
debug1: Reading configuration data /home/alagris/.ssh/config
debug1: /home/alagris/.ssh/config line 1: Applying options for Oelkozadam
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "oelkozadam" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to oelkozadam [192.168.7.145] port 22.
debug1: Connection established.
debug1: identity file /home/alagris/.ssh/test type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/alagris/.ssh/test-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.3
debug1: match: OpenSSH_7.3 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to oelkozadam:22 as 'alagris'
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nist p521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,dif fie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: [email protected],ecdsa-sha2-nistp384-cert-v01@openss h.com,[email protected],[email protected],ssh-rsa-cert-v01@openssh. com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed2551 9,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected] om,[email protected],aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected] om,[email protected],aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc
debug2: MACs ctos: [email protected],[email protected],[email protected],hmac-sh [email protected],[email protected],[email protected],[email protected],hmac-sha2-256,h mac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],hmac-sh [email protected],[email protected],[email protected],[email protected],hmac-sha2-256,h mac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected],zlib
debug2: compression stoc: none,[email protected],zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nist p521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,dif fie-hellman-group14-sha256,diffie-hellman-group14-sha1
debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected] om,[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected] om,[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],hmac-sh [email protected],[email protected],[email protected],[email protected],hmac-sha2-256,h mac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],hmac-sh [email protected],[email protected],[email protected],[email protected],hmac-sha2-256,h mac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected]
debug2: compression stoc: none,[email protected]
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:LOy/ttmSoIpf6+H0jRYCVveaNrhjTRDV61fCx6CQxQ4
The authenticity of host 'oelkozadam (192.168.7.145)' can't be established.
ECDSA key fingerprint is SHA256:LOy/ttmSoIpf6+H0jRYCVveaNrhjTRDV61fCx6CQxQ4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'oelkozadam,192.168.7.145' (ECDSA) to the list of known hosts.
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug2: key: /home/alagris/.ssh/test (0x55ad2b5b8360), explicit, agent
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 53
debug3: input_userauth_banner
Welcome to Oelkozadam's remote workstation. Intruders are not so welcome.
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/alagris/.ssh/test
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
These are the permissions:
chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys
chown alagris:users ~/.ssh/authorized_keys
I have generated keys with this command:
ssh-keygen -b 3072 -f "~/.ssh/$key" -P "$pass" -C "$(whoami)@$(hostname)-$(date -I)"
and used cat to append public key to ~/.ssh/authorized_keys
~/.ssh/config looks as follows:
Host Oelkozadam
IdentitiesOnly yes
IdentityFile ~/.ssh/test
/etc/ssh/sshd_config looks as follows:
Port 22
AddressFamily any
ListenAddress 192.168.7.145
AllowUsers remote_user alagris
PermitRootLogin no
Banner /my/config/SSH_ServerBanner
PasswordAuthentication no
ChallengeResponseAuthentication no
AuthorizedKeysFile ~/.ssh/authorized_keys
ChallengeResponseAuthentication no
UsePAM yes
Subsystem sftp /usr/lib/ssh/sftp-server
PrintMotd no
"$systemctl edit sshd.socket" looks as follows:
[Socket]
ListenStream=
ListenStream=22
I have no idea what else I could to make it work. I also tried to SSH from my Mac laptop via LAN but I get similar results.
(edit:I removed all files in ~/.ssh and generated test and test.pub from scratch, added test.pub to ~/.ssh/authorized_keys,once again set permissions on all these files, rebooted computer, ran
eval $(ssh-agent)
ssh-add ~/.ssh/test
and connected again. The output slightly changed. Now it says:
Offering RSA public key: /home/alagris/.ssh/test
The previous:
Offering RSA public key: /my/config/SSH/test
was probably fault of some unapplied changes which got updated after reboot.
Also, an interesting fact is that as I recreated authorized_keys file, the key that I generated for my Mac computer was lost and yet the output of ssh connection is absolutely the same. It's very similar to output on local machine but the end:
send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/alagris/.ssh/id_dsa
debug3: no such identity: /Users/alagris/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /Users/alagris/.ssh/id_ecdsa
debug3: no such identity: /Users/alagris/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /Users/alagris/.ssh/id_ed25519
debug3: no such identity: /Users/alagris/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
)
PS. I wish I could see any logs coming directly from server but it seems on ArchLinux there are no files like /var/log/auth.log. I can olny view journalctl which seems to be quite empty.
|
I have no idea what happened. I kind of gave up but then after a few reboots it just magically started working.
| SSH to localhost server [closed] |
1,461,309,630,000 |
Three server A,B & C. How to ssh connect from A to C via intermediate server B, if A to B & C to B are password less(key)? I encountered this in an interview. Anyone knows how?
|
The original question does not make much sense. But I can guess they wanted to ask about the servers A and C in private networks (so they do not "see" each other) and B visible to both of them. In this case, the answer is Remote Port Forwarding. With example:
Create a tunnel B->C from C:
C$ ssh -R 2222:localhost:22 B
and then connecting from A to C like this:
A$ ssh A ssh -p 2222 localhost
Or in more elegant way with ssh_config. You will have to certainly write the password to connect to the server C (localhost:2222 from B), if there is not set up pubkey authentication, but that should not be a problem.
| How to SSH via intermediate server [duplicate] |
1,461,309,630,000 |
What do I have to do to be able to access my local network over ssh with a dynamic IP address?
|
Use a dynamic DNS service. This is basically a little script or daemon that calls into a dns server so it gets updated whenever the IP changes. There are a number of providers for this service. For home use or only a few addresses you can use a free service like duck dns. I've used them since dyndns kicked off all their free customers and haven't had any problems. This assumes that you have a server that is publicly available and it is listening on some port (22 by default) for ssh connections. If you don't have the server set up edit your question with the set up you have we we can add more steps.
| How to access my local network from anywhere over ssh? |
1,461,309,630,000 |
I am unable to connect to ssh despite the fact that PermitRootLogin option is set to "yes" in my sshd_config.
ssh localhost
root@localhost's password:
Permission denied, please try again.
Here is my full sshd_config:
PasswordAuthentication yes
ChallengeResponseAuthentication no
UsePAM yes
X11Forwarding yes
PrintMotd no
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
PermitRootLogin yes
AllowUsers otheruser
What prevent the ssh connection as root and how to fix it?
|
AllowUsers
If specified, login is allowed only for user named that match one of the patterns.
Add root to the list:
AllowUsers root otheruser
| Cannot use root ssh despite option "PermitRootLogin yes" in sshd_config |
1,461,309,630,000 |
There are two (unix) users who are allowed to connect to my Debian Wheezy server using ssh: git and peter. While git is allowed to connect from everywhere, peter (who is in the sudo group) should be only allowed to connect from my local network.
I therefore added the line
AllowUsers git [email protected]/24
to my /etc/ssh/sshd_config
And it first seemed to work, as git is allowed to connect remotely over the internet, while peter isn't.
My desktop, which has the ip address 192.168.2.24 is allowed to connect as peter, but my laptop isn't when connected using VPN (with local ip 192.168.2.201). It works when using it directly connected to my LAN.
This is what I can find in the /var/log/auth.log file. It doesn't make any sense to me, why is that IP not allowed?
Feb 2 11:44:54 srv sshd[7275]: User peter from 192.168.2.201 not allowed because not listed in AllowUsers
Feb 2 11:44:54 srv sshd[7275]: input_userauth_request: invalid user peter [preauth]
|
Use:
AllowUsers git [email protected].*
or for example:
AllowUsers git [email protected]??
if only 200-254 are allocated for VPN connections.
And make sure to read man ssh_config (the section PATTERNS). Yes, that's ssh_config, not sshd_config. But if you read the latter, you'll notice it refers to the former.
| Restrict SSH login to local network: VPN connection not allowed |
1,461,309,630,000 |
Having a problem installing an openssh rpm I hand-rolled today:
[root@local_host ]# rpm -i openssh-6.7p1-1.i386.rpm
error: Failed dependencies:
libcrypto.so.1.0.0 is needed by openssh-6.7p1-1.i386
Huh? That's strange:
[root@local_host ]# ls -l /lib/libcrypto*
lrwxrwxrwx 1 root root 19 Jan 20 15:18 /lib/libcrypto.so.1.0.0 -> libcrypto.so.1.0.1l
-rwxr-xr-x 1 root root 1815536 Jan 19 04:57 /lib/libcrypto.so.1.0.1l
Dependencies of rpm seem to list same file I have installed:
[root@local_host ]# rpm -qpR openssh-6.7p1-1.i386.rpm
config(openssh) = 6.7p1-1
...
libcrypto.so.1.0.0
I can force the installation and it works - of course, since the required lib is installed - but, what would cause this to have gone all wonky?
I did run ldconfig post-install of my new openssl (also hand-rolled), so the libs should be visible to the system.
Box is CentOS 5.4.
Additional Info
Per @nlu, I checked which package owns the file(s) in question. The file that the ssh rpm wants is actually a symlink to the actual file.
[root@local_host ~]# rpm -qf /lib/libcrypto.so.1.0.0
file /lib/libcrypto.so.1.0.0 is not owned by any package
[root@local_host ~]# rpm -qf /lib/libcrypto.so.1.0.1l
openssl-1.0.1l-1
But it doesn't appear in the rpm:
[root@local_host ~]# rpm -ql openssl-1.0.1l-1
...
/lib/libcrypto.so.1.0.1l
...
So, I did some more work. Figured out how to package up the symlinks in the rpm, also fixed the names to reflect the standard install of openssl and respun the rpm. Installed that without issue. Then, went to install openssh and received exactly the same error!
On the box, I now have:
[root@local_host ]# ls -l /lib/libcrypto*
lrwxrwxrwx 1 root root 27 Jan 21 14:16 /lib/libcrypto.so.1.0.0 -> /usr/lib/libcrypto.so.1.0.0
lrwxrwxrwx 1 root root 27 Jan 21 14:16 /lib/libcrypto.so.6 -> /usr/lib/libcrypto.so.1.0.0
[root@local_host ]# ls -l /usr/lib/libcrypto*
lrwxrwxrwx 1 root root 27 Jan 21 14:16 /usr/lib/libcrypto.so -> /usr/lib/libcrypto.so.1.0.0
-rwxr-xr-x 1 root root 1815536 Jan 21 05:43 /usr/lib/libcrypto.so.1.0.0
[root@local_host ]# rpm -ql openssl-1.0.1l
...
/lib/libcrypto.so.1.0.0
/lib/libcrypto.so.6
/usr/lib/libcrypto.so
/usr/lib/libcrypto.so.1.0.0
Everything should now be in place, I should think? What have I missed?
|
Aha!
I added:
Provides: libcrypto.so.1.0.0 libssl.so.1.0.0
to the spec file, respun and installed. NOW.... openssh installs without question!
Question now is.... WHY? I don't see a lib or pre-requisite in the openssh.spec file.
Update
Thanks to Mark for putting me onto the requires bits... figured out that I had the AutoReqProv attribute set to No... should have been yes. Works as it should now (don't have to add the Provides line above), thanks!
| RPM Says Shared Object Is Missing But I Can Find It With ls |
1,461,309,630,000 |
I'm connected to Ubuntu server that is a member of a corporate Active Directory domain via likewise-open. The users are in the form mydomain\myuser. I can connect to it via ssh, escaping the \ with another \:
ssh mydomain\\myuser@myserver
I've generated a pair of keys via ssh-keygen, then tried to copy it to the remote machine. The user I'm using in the local machine is not the same I want to copy the key into, so I issued the command:
ssh-copy-id mydomain\\myuser@myserver
and the output:
password:
password:
password:
mydomainyuser@myserver's password:
Received disconnect from myserver: 2: Too many authentication failures for myuserydomain
prompting me for the local user's password three times, and then the \\ actually worked as a single \ escaping the first m in mydomain. Am I getting this straight? And how can I escape that \ and correctly copy key to the remote machine?
EDIT: also ssh-copy-id [email protected]@myserver turned out to be a valid syntax.. However, the question was about escaping the \.
|
The reason this is happening is because you are escaping it for the shell, but ssh-copy-id is also attempting to interpret it. This should work:
ssh-copy-id 'mydomain\\myuser@myserver'
| how to escape "\"in ssh-copy-id? |
1,461,309,630,000 |
For those who worked with ssh port forwarding or for those who have an idea, I managed to create a remote tunnel from my PC to a remote machine(a camera that does not have a public address) through a ssh server ( has a public address ).
The goal is to forward the access of the camera to the public with ssh remote port forwarding,
The format of the command that I launched on my PC is:
ssh -R sshServer_port:destination_address:destination_port sshServer_address
Example:
ssh -R 3000:192.198.1.210:80 [email protected]
In the sshServer, I can access the remote machine through localhost:3000
and then, I set up a tcpproxy to make the access public with this command:
tcpproxy -lhost 0.0.0.0:8080 -rhost localhost:3000
With this,anyone from any network can access to the camera interface by typing 52.14.9.210:8080
What I want to do is create a tunnel that listens on two remote machine ports (80 for http and 8000 for the live streaming) with the format of the command:
ssh -R sshServer_port:destination_address:destination_port1 -R sshServer_port:destination_address:destination_port2 sshServer_address
Example:
ssh -R 3000:192.168.1.210:80 -R 3000:192.168.1.210:8000 [email protected]
I tried to run the command but I got this error: Warning: remote port forwarding failed for listen port 3000
Do you have an idea how to fix this.
|
What you want is not to create a tunnel that listens on two remote machine ports, you want two tunnels that listen on the same remote port.
That is not possible. How is ssh supposed to know to which port an incoming connection should be forwarded?
There are solutions that can distinguish between protocols, but none of them are generic. It the port 80 you use is an indication of http traffic, you can set up a reverse proxy, but it would be much easier to just use two different ports for the two destinations.
Edit
From your comments, it seems you are just missing the -g option to SSH to allow other hosts to connect to the tunnel.
| SSH Remote port forwarding with multiple ports |
1,461,309,630,000 |
I am trying to set up my Openssh server to allow for chrooted sftp-only users as well as for non-chrooted sftp and ssh users. My condensed (comments and blank lines removed) /etc/ssh/sshd_config looks like this:
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp intenal-sftp
UsePAM yes
Match Group sftpusers
ChrootDirectory /var/sftp/%u
ForceCommand internal-sftp
What I have achieved by this:
Users in the sftupsers group can sftp their files into their directories, but can't log in. Check.
Users, who are not in sftpusers can login via ssh. Check.
Users, who are not in sfttpusers can not sftp files. Oops.
If I change the Subsystem sftp-line to the commented out version, the "privileged" users can sftp and ssh, but the chrooted users can no longer sftp.
With the above config-file I get the error message Connection closed by server with exitcode 127 from FileZilla and Fatal: Received unexpected end-of-file from SFTP server from psftp.
Any idea how to fix this?
|
Subsystem sftp intenal-sftp
Should be "internal".
| How to set up chrooted and non-chrooted sftp? |
1,461,309,630,000 |
I have a lot of ssh public key logins on a Linux server, e.g.:
Jul 25 11:41:01 host sshd[24594]: Accepted publickey for root from xxx.xxx.xx.xx port 33374 ssh2
This is strange for me since there's no authorized_keys file in the /root/.ssh directory. The AuthorizedKeysFile option in /etc/ssh/sshd_config has the default value of .ssh/authorized_keys.
I wonder how is it possible to login to the server using public key authentication?
|
I've figured out what's going on. The messages are coming to the server from remote hosts via UDP. I didn't notice the host field changing at first, my mistake.
BTW, actually there is a possibility to login using public key authentication with no authorized_keys file involved. RedHat (and variants) have a supported patch for OpenSSH that adds the AuthorizedKeysCommand and AuthorizedKeysCommandRunAs options. The patch has been merged upstream in OpenSSH 6.2. To quote from the man page:
AuthorizedKeysCommand
Specifies a program to be used for lookup of the user's public keys.
The program will be invoked with its first argument the name of the
user being authorized, and should produce on standard output
AuthorizedKeys lines (see AUTHORIZED_KEYS in sshd(8)). By default (or
when set to the empty string) there is no AuthorizedKeysCommand run.
If the AuthorizedKeysCommand does not successfully authorize the user,
authorization falls through to the AuthorizedKeysFile. Note that this
option has an effect only with PubkeyAuthentication turned on.
AuthorizedKeysCommandRunAs
Specifies the user under whose account the AuthorizedKeysCommand is
run. Empty string (the default value) means the user being authorized
is used.
| public key authentication without authorized_keys file |
1,461,309,630,000 |
I have many reverse ssh tunnels and because monitoring ports can't be reused, I am trying to find a free random port for monitoring.
Meanwhile I specified -M 0 and the forwards work great and in most cases: when there is a disconnection, it will automatically reconnect. However, sometimes, on rare occasion, a connection will hang and think it is connected even if it has gone stale.
Is it possible to setup a random monitoring port?
What I tried:
When I specify a port with -M [port] , I can't monitor more than one connect
When I specify -M 0 and use ServerAlive, rarely the connection hangs
I added ClientAlive in sshd_config and specify ServerAlive in the command line
Because my reverse port forward occasionally becomes stale, it makes it unreliable
|
I ended up finding the answer:
have an echo server on the ssh server and specify that as the monitoring port for all connections (better but requires setting up an echo server)
find an available port range and have a way for each connection to create a unique port forward on a different port.
| Specifying a random monitoring port with autossh |
1,461,309,630,000 |
I am running an OpenVPN server on Ubuntu 14.04 as well as OpenSSH.
I have my SSH server configured to bind to an IP address on my VPN interface. Once my machine boots, binding to that IP fails.
Once I log in, can see with netstat that sshd is not listening. I am able to restart sshd and the machine will start listening properly. The IP on my VPN is the only IP I have configured sshd to listen on.
At Boot:
sshd[1016]: Set /proc/self/oom_score_adj from 0 to -1000
sshd[1016]: error: Bind to port 22 on 10.8.0.1 failed: Cannot assign requested address.
sshd[1016]: fatal: Cannot bind any address.
Restart SSH:
sshd[3481]: Set /proc/self/oom_score_adj from 0 to -1000
sshd[3481]: Server listening on 10.8.0.1 port 22.
My best guess is that sshd is starting before my VPN is up and running. Is there a way I am able to ensure sshd starts afterwards so it can bind properly?
Any suggestions about what to do or check?
|
I found a solution.
In the OpenVPN configuration file /etc/openvpn/server.conf you can specify a script to run on up. If you take a look at the OpenVPN manual page man openvpn, you will see --up cmd. In the /etc/openvpn/server.conf configuration file, I added a line:
up "/etc/openvpn/up.sh"
This file is one that I created and will be executed when the VPN starts. Right now, mine looks like this:
#!/bin/sh
logger VPN is UP
service ssh restart
Now, every time my OpenVPN server starts up, it will also restart the OpenSSH server as well. Likewise, I am able to also use --down cmd and specify a file in the server configuration file if I wish to have a script executed when the server is shutdown.
You can read more about these in the OpenVPN manual page - man openvpn
| Starting SSH server after VPN starts |
1,461,309,630,000 |
I wanted to forward my local 8080 port to the 80 port of the server I want to log in via SSH, so I did:
ssh -L 80:127.0.0.1:8080 -N -f myserver
But I get the error:
Privileged ports can only be forwarded by root.
I can execute sudo commands when logged in that server, but how can I do it for the purposes of port forwarding? (Note: appending sudo at the beginning of this command doesn't help, because the port 80 is not the port I want to use in localhost, but the port I want to target.)
|
You probably want
ssh -L 8080:127.0.0.1:80 -N -f myserver
Local port comes first. (That's not my political stance!)
| SSH port forwarding: "Privileged ports can only be forwarded by root" error |
1,461,309,630,000 |
This post is about applying the latest patch for OpenSSL to protect our port 443 web traffic, not using ssh to log into these systems.
I went and obtained the lastest OpenSSL tarball source patch openssl-1.0.1g.tar.gz from here for my Linux workstation running CentOS 6.5, and built the patch, including
./config; make; make test; make install # as root
This installed in /usr/local/ssl.
I wanted to prove the patch out in a safe place, before applying it to our production systems. However, after running everything, I'm stumped. The
./config, make, make test, and make install
steps completed without errors.
How do I check that the latest OpenSSL is installed?
Here is the result of testing version from various answers:
openssl version -a
OpenSSL 1.0.1e-fips 11 Feb 2013
built on: Tue Apr 8 02:33:43 UTC 2014
platform: linux-elf
|
Preamble: As observed in the question, openssl installs by default into /usr/local/ssl. My recommendation is to use ./config --prefix=/usr/local shared (notice the space before "shared") so that it installs there (and builds the shared library, libssl), rather than its own private subdirectory. If you do not do this, you will have to add a file to /etc/ld.so.conf.d with /usr/local/ssl/lib in it (see below for the significance of /etc/ld.so.conf.d files), and add /usr/local/bin to $PATH.
You will need to run ldconfig after make install to add the libraries to the linker cache. If that doesn't work, read on.
make install probably by default went to /usr/local, which should take precedence but may not. You can thus leave your distro's openssl install to avoid messing around with the package manager and prereqs, but still use your own locally built version as the default. To check:
ldd $(which ssh) | grep libssl
If you get no output, your ssh was statically linked and needs to be rebuilt (see Anton's answer). Otherwise, this should point to your /usr/local version. If it points to something else:
ldconfig -p | grep libssl
The /usr/local version should be shown, but after some other one. If so, skip down to "/usr/local/lib does not have precedence" below. If not, make sure /usr/local is in the linker path generally:
ldconfig -p | grep "/usr/local"
If not, grep -r "/usr/local" /etc/ld.so.conf.d. If that is not there, add a file to /etc/ld.so.conf.d called 00-local.conf with one line:
/usr/local/lib
Run ldconfig (no switches) and go through this again.
/usr/local/lib does not have precedence
Find the linker cache config file where the path is added:
grep -r "/usr/local" /etc/ld.so.conf.d
If it's not there, you'll have to add a file as explained above. Presuming it is, the problem is the files are processed lexicographically. E.g., if the content of /etc/ld.so.conf.d is:
addtheselibraries.conf
libc.conf
And libc.conf contains /usr/local/lib but addtheselibraries.conf contains, e.g. /usr/lib,1 then the latter will take precedence. If the /usr/local/lib file doesn't contain anything else, just rename it with something which will supersede the other files; numbers go first so 000-whatever is good.
Because you have complete control over /usr/local/lib, it should take precedence over any paths used by the distro package manager (and usually does).
1. /usr/lib is a default compiled into the linker, but it and other standard system places (/lib, etc) are added last, which allows you to supersede them. Because of these, sometimes (e.g.) /usr/lib is added to a .conf file in order to make it supersede some other .conf file.
| How I Determine The latest OpenSSL patch is installed? |
1,461,309,630,000 |
My sftp -v to host returns,
Connecting to xxx.xx.xx.xx...
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to xxx.xx.xx.xx [xxx.xx.xx.xx] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_dsa type 2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_3.9p1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'xxx.xx.xx.xx' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:63
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Offering public key: /root/.ssh/id_dsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
[email protected]'s password:
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
Read from remote host xxx.xx.xx.xx: Connection reset by peer
debug1: Transferred: stdin 0, stdout 0, stderr 61 bytes in 0.0 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 60334.5
debug1: Exit status -1
This only occurs with this user. I created a test user which works and other existing users don't have and issue (well no reported issues by users).
|
Answer by narcisgarcia @ http://ubuntuforums.org/showthread.php?t=1482005 solved my problem.
Summary: "Owner of the destination directory must be "root", and group/other users cannot have write permissions."
| SFTP, SSH Couldn't read packet: Connection reset by peer [duplicate] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.