date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,461,309,630,000 |
Setup:
I have a system in bash where I have a single file that spawns off a pipeline of background processes.
In stage one of the pipeline, there are multiple processes writing to a single named pipe. In the next stage of the pipeline there is a reader process which reads the named pipe and passes the data off to other worker processes to operate on the data. (See example script below). These workers can return the data back into the stage2 pipeline if it is determined the data isn't ready via communicating with remote resources via https.
Problem:
The setup was working great with a non-trivial load until I added a ssh call inside the worker processes in the second stage of the pipeline. Once I did that a lot of the data going through the named pipe started disappearing. This happens even if I significantly reduce the load to only 2% of what was previously working.
I did some reading and I found a few vague references to the ssh client destroying fds so I wasn't sure if this was related.
Environment: I'm currently using bash 5.0.17 on Ubuntu 20.04. I've also tested on an Ubuntu 22.04 system and saw the same behavior.
Simplified script
#!/bin/bash
function stage1_worker()
{
# Do work including network calls via a 3rd party program which uses python
flock --exclusive $QUEUE -c "print \"%s\n\" $DATA > $QUEUE"
}
function stage2_reader_v1()
{
local QUEUE_DATA=""
while true ;
do
# logic
if read QUEUE_DATA ; then
stage2_worker $QUEUE_DATA &
fi
# logic
done < $QUEUE
}
function stage2_worker_v1()
{
local QUEUE_DATA=$1
local retry_needed=false
# logic
# Add back to the stage 2 queue if retry needed (reader rate limits to stage 2 worker to keep process count down)
if $retry_needed ; then
flock --exclusive $QUEUE -c "print \"%s\n\" $DATA > $QUEUE"
fi
}
QUEUE=$(mktemp -u)
mkfifo $QUEUE
trap "rm -f $QUEUE" EXIT
# Launch stage 2 reader in background process
stage2_reader &
# Launch several stage 1 workers...
stage1_worker $ARG &
# wait for all background processes to complete
wait
When I made this change, suddenly my queue started dropping data and items weren't being processed
function stage2_worker_v2()
{
local QUEUE_DATA=$1
local retry_needed=false
# logic
local IP_FROM_QUEUE_DATA=... #logic
ssh -o ConnectTimeout=1 -o BatchMode=yes user@$IP_FROM_QUEUE_DATA '<remote command' >/dev/null 2>&1
if [[ $? -ne 0 ]] ; then
#handle failure
fi
# Add back to the stage 2 queue if retry needed (reader rate limits to stage 2 worker to keep process count down)
if $retry_needed ; then
flock --exclusive $QUEUE -c "print \"%s\n\" $DATA > $QUEUE"
fi
}
In my quest to limit permanently open fds I changed the reader to this which improved throughput, but I was still missing data
function stage2_reader_v1()
{
local QUEUE_DATA=""
while true ;
do
# logic
if read -t 1 QUEUE_DATA <> $QUEUE ; then
stage2_worker $QUEUE_DATA &
fi
# logic
done
}
Removing the ssh call from the stage2_worker_v2 results in all data flowing through the pipeline as expected.
I'd appreciate any understanding of why this is happening and how to mitigate it.
I wrote this simplified script quickly, there may be minor syntax/naming errors that aren't present in my real code.
|
It shouldn't interfere with the named pipe, but it does interfere with stdin, namely trying to read from it. When you call stage2_worker, stdin is redirected from the pipe, that carries on the to the ssh process.
while true; do
if read QUEUE_DATA ; then
stage2_worker $QUEUE_DATA &
fi
done < $QUEUE
function stage2_worker_v2()
{
...
ssh -o ConnectTimeout=1 -o BatchMode=yes user@$IP
Either redirect the stdin of ssh from somewhere else, e.g. ssh ... < /dev/null (or just use ssh -n which does essentially the same), or do the redirection in the while loop so that it doesn't interfere with the stdin of the stuff inside the loop. There's a few variations:
Tell read to read from fd 3, and redirect the input there (Bash):
while true; do
if read QUEUE_DATA -u 3; then
stage2_worker $QUEUE_DATA &
fi
done 3< $QUEUE
Same but with another redirection:
while true; do
if read QUEUE_DATA <&3; then
stage2_worker $QUEUE_DATA &
fi
done 3< $QUEUE
Or do the redirection from the pipe only for read:
while true; do
if read QUEUE_DATA < $QUEUE; then
stage2_worker $QUEUE_DATA &
fi
done
In any case, you may want to consider quoting those variable expansions, just in case any of your values ever contain whitespace or glob characters. Also, the standard way to declare a function is funcname() while function funcname() is a mix of the ksh style and the standard way, and is only supported in Bash (AFAIR).
| Does ssh client interfere with named pipes? [duplicate] |
1,461,309,630,000 |
Say an authorized key is restricted to the command to test parameters, eg command="bin/testparameters" and the ssh call is:
ssh user@host 'some parameters which may include other commands'
How can bin/testparameters read the value 'some parameters which may include other commands'.
|
The additional parameters passed to ssh appear in the environment variable SSH_ORIGINAL_COMMAND:
$ tail -1 .ssh/authorized_keys
command="printf '%s\n' \"$SSH_ORIGINAL_COMMAND\"" ssh-rsa AAAA....kz6C5 [email protected]
$ ssh [email protected] foo bar farkle
foo bar farkle
| When an SSH authorized key is restricted to command how can the command read the parameters in the call? |
1,461,309,630,000 |
I'm trying to troubleshoot a sudden outbreak of short-lived SSH connections. These connections are initiated from my Mac (MBP, Catalina 10.15.6, zsh) to some of the Linux "appliances" that live on my network here - in particular the Raspberry Pies. After the connections terminate, they leave the message client_loop: send disconnect: Broken pipe in the terminal.
However: That's offered only as background in case it's related to my immediate question:
Why does the command ssh-agent -k not kill ssh-agent?
It appears to fail because the environment variable SSH_AGENT_PID is not set. I have guessed that based on what I see in my Mac terminal app:
1. list ssh-related processes:
% pgrep -f ssh
2138
75076
75942
75943
75944
% ps 2138
PID TT STAT TIME COMMAND
2138 ?? S 0:00.26 /usr/bin/ssh-agent -l
PID 2138 is ssh-agent, the other PIDs are active ssh connections to Raspberries or Ubuntu box - all Linux.
2. kill ssh-agent IAW man ssh-agent:
From man ssh-agent:
ssh-agent [-c | -s] -k
-k Kill the current agent (given by the SSH_AGENT_PID environment variable).
% ssh-agent -k
SSH_AGENT_PID not set, cannot kill agent
% sudo ssh-agent -k
SSH_AGENT_PID not set, cannot kill agent
% echo $SSH_AGENT_PID
%
I can kill ssh-agent using kill 2138, or with pkill ssh-agent, and so it seems that perhaps the answer is Apple's version of ssh-agent doesn't provision the environment variable SSH_AGENT_PID. But if that's the answer, it raises another question: Is there a valid reason for not assigning the environment variable SSH_AGENT_PID?
Also note that a related question. However, the OP for that question didn't identify his SSH client host was macOS. He also indicated SSH_AGENT_PID was not set, but seemed concerned only with how ssh-agent was started. In my case (macOS), ssh-agent is started when an ssh connection is initiated. I found other Q&A in the "Similar Questions" suggestion box; I read a few of them, but none seem the same as mine.
|
See this answer.
From the man page:
When ssh-agent
is started, it prints the shell commands required to set its
environment variables, which in turn can be evaluated in the
calling shell, for example eval `ssh-agent -s`
So running ssh-agent just shows the commands to set the environment variables, not actually sets them, unless you use eval.
| Why does `ssh-agent -k` not kill ssh-agent (macOS), or why is `SSH_AGENT_PID` not set? |
1,461,309,630,000 |
When I run:
ssh-keygen -t rsa
to generate a public/private key pair in files e.g. id_rsa.pub and id_rsa, my understanding is that the public key encodes a prime number p, and the private key encodes a number pq. But when I open these files I don't see human-readable numbers, I see sequences of characters. So my question is simply: what am I looking at? Are these characters directly mappable to numbers and, if so, by what convention/algorithm/encoding?
|
The ssl keys (private and public) are usually stored in so named PEM format.
Privacy-Enhanced Mail (PEM) is a de facto file format for storing and
sending cryptographic keys, certificates, and other data, based on a
set of 1993 IETF standards defining "privacy-enhanced mail." While the
original standards were never broadly adopted, and were supplanted by
PGP and S/MIME, the textual encoding they defined became very popular.
The PEM format was eventually formalized by the IETF in RFC 7468.
This format is actually header, then base64 encoded binary data and footer.
Base64 is a group of similar binary-to-text encoding schemes that
represent binary data in an ASCII string format by translating it into
a radix-64 representation. The term Base64 originates from a specific
MIME content transfer encoding. Each Base64 digit represents exactly 6
bits of data. Three 8-bit bytes (i.e., a total of 24 bits) can
therefore be represented by four 6-bit Base64 digits.
For ssh keys please check below from dave_thompson_085 comments:
Note ssh-keygen uses (several) PEM formats but never the one(s) in
7468. In the past for RSA it defaulted to OpenSSL's two 'traditional' (aka 'legacy') formats, either unencrypted whcih is 7468-like except
containing PKCS1, or password-encrypted which is1421-like with
Proc-type and DEK-Info and base64 of encrypted PKCS1, but not
7468-like. Since 7.8 it defaults to OpenSSH's own 'new format'
(previously invoked by option -o) which is 7468-like but the contents
are entirely different (XDR-style not ASN.1). There are numerous Qs
about these already on several Stacks.
OpenSSH public key formats are never PEM (although commercial 'SSH2'
sort-of are), just base64 of SSH wire format. And I was recently
reminded this Q/A covers the private key formats quite thoroughly
| What encoding is used for the keys when using `ssh-keygen -t rsa`? |
1,461,309,630,000 |
I'm using OpenSSH_5.8p1 in my machine,I'm connecting my machine using putty client but its slower so I have ran sshd in debug mode and found following messages can any one explain me in detail about each messages?
debug1: sshd version OpenSSH_5.8p1
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: read PEM private key done: type ECDSA
debug1: private host key: #2 type 3 ECDSA
debug1: rexec_argv[0]='/sbin/sshd'
debug1: rexec_argv[1]='-d'
Set /proc/self/oom_adj from 0 to -17
debug1: Bind to port 22 on 0.0.0.0.
Server listening on 0.0.0.0 port 22.
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 6 out 6 newsock 6 pipe -1 sock 9
debug1: inetd sockets after dupping: 4, 4
Connection from 192.168.0.57 port 33962
debug1: Client protocol version 2.0; client software version PuTTY_Release_0.63
debug1: no match: PuTTY_Release_0.63
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.8
debug1: list_hostkey_types: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: client->server aes256-ctr hmac-sha1 none
debug1: kex: server->client aes256-ctr hmac-sha1 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST_OLD received
debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent
delay of 1.5 second
debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT
debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
delay of 1.8 second
debug1: KEX done
Connection closed by 192.168.0.57
|
This question sounds like a case of the XY problem; you're asking for something that probably doesn't help you with the problem you actually want to solve. Perhaps you should be more careful what you ask for, but for the sake of general knowledge, here goes..
debug1: sshd version OpenSSH_5.8p1
This indicates that the version of OpenSSH is 5.8p1
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: read PEM private key done: type ECDSA
debug1: private host key: #2 type 3 ECDSA
This indicates that OpenSSH found three host keys, which are used to convince the client that the remote is indeed the host the client intended to connect to. The keys are for the RSA, DSA and Elliptic Curve DSA cryptographic algorithms.
debug1: rexec_argv[0]='/sbin/sshd'
debug1: rexec_argv[1]='-d'
These are the arguments the ssh daemon was invoked with.
Set /proc/self/oom_adj from 0 to -17
This indicates that the ssh daemon disables the kernel Out-of-Memory Killer altogether for this process.
debug1: Bind to port 22 on 0.0.0.0.
Server listening on 0.0.0.0 port 22.
This indicates the server is listening for connections to port 22 from any IPv4 source address.
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
This indicates the server is listening for connections to port 22 from any IPv6 source address.
debug1: Server will not fork when running in debugging mode.
Normally sshd forks a new process for each incoming connection. Since the -d options was specified when sshd was invoked, it runs in debugging mode and does not fork and will only process one connection.
debug1: rexec start in 6 out 6 newsock 6 pipe -1 sock 9
debug1: inetd sockets after dupping: 4, 4
This indicates that some communication sockets were duplicated.
Connection from 192.168.0.57 port 33962
debug1: Client protocol version 2.0; client software version PuTTY_Release_0.63
debug1: no match: PuTTY_Release_0.63
debug1: Enabling compatibility mode for protocol 2.0
This indicates an incoming connection was received from a Putty client. The ssh daemon does not recognize the particular version string sent by the client, so it will operate in a mode compatible with the SSH protocol version 2 specification.
debug1: Local version string SSH-2.0-OpenSSH_5.8
debug1: list_hostkey_types: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256
This indicates that the ssh daemon identified itself as an SSH 2.0 compatible OpenSSH daemon. The hostkey types indicate the cryptographic algorithms the ssh daemon supports for performing host authentication.
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: client->server aes256-ctr hmac-sha1 none
debug1: kex: server->client aes256-ctr hmac-sha1 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST_OLD received
debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent
delay of 1.5 second
debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT
debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
delay of 1.8 second
debug1: KEX done
These messages indicate that a Diffie-Hellman Group Exchange was performed to exchange key material. After the protocol completes, the client and server have agreed upon a session key used to encrypt further communication using the AES cryptographic algorithm with 256 bit keys in Counter mode and the SHA1 cryptographic hash algorithm for the hash-based message authentication code.
Connection closed by 192.168.0.57
This indicates that the connection was closed by the client.
| Understand debug messages from sshd [closed] |
1,542,878,501,000 |
When I use netcat to connect to an SSH port of a Debian system (nc host 22), I got the response SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u1. What does this Debian-10 mean? The host is on Debian 9.
|
It simply reflects the Debian revision of the package currently in Debian 9; see the package page for details. The current version is 1:7.4p1-10+deb9u1; you can ignore the “1:”, then “7.4p1” is the version of OpenSSH, and “10+deb9u1” means this is the tenth release of the Debian package, updated for Debian 9 for the first time (more strictly, this is the first Debian 9 update following the tenth release of the Debian package of OpenSSH 7.4p1). The Debian changelog lists the changes made in the successive Debian packages of OpenSSH 7.4p1.
Put another way, “Debian-10+deb9u1” means it’s OpenSSH as packaged by Debian, and the Debian part of the version number (which is specific to the OpenSSH package) is “10+deb9u1”. The 10 there has nothing to do with the Debian release.
| What does the "Debian-10" mean in the response of the ssh server "SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u1" mean? |
1,542,878,501,000 |
My users are shared across a number of machines via LDAP.
For one of those machines (let's call it 'fileserf'), I would like to restrict some users in what they can do (actually: prevent them from logging into an interactive session via ssh).
On the other machines, these users should be able to use ssh normally.
So my initial idea was to use the internal-sftp subsystem, along the lines of:
Match group sftponly
ChrootDirectory %h
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
This works ok as it restricts only the members of the (local) group sftponly on a single host fileserf, but unfortunately the internal-sftp subsystem only allows sftp and not scp (or rsync).
So I did some more research and found rssh, which seems to allow me to do exactly what I want to do (permission-wise).
Now the problem is that I cannot set the login-shell of those users to /usr/bin/rssh in my LDAP, because that would mean that they would be restricted on all machines, not just on fileserf.
So my idea is to override the login shell via some configuration in fileserf's sshd_config:
Match group sftponly
X11Forwarding no
AllowTcpForwarding no
ForceCommand /usr/bin/rssh
Unfortunately this doesn't seem to work, since now the users get a Connection closed whenever they try to sftp into the machine:
$ ssh user@fileserf
This account is restricted by rssh.
Allowed commands: scp sftp
If you believe this is in error, please contact your system administrator.
Connection to fileserf closed.
$ sftp user@fileserf
Connection closed
$
How can I make ForceCommand work with rssh?
Alternatively, How can I configure sshd to override the login-shell for a group of users?
|
The rssh manpage indicates it should be the login shell of these users:
The system administrator should install the shell on the restricted
system. Then the password file entry of any user for whom it is
desireable to provide restricted access should be edited, such that
their shell is rssh. For example:
luser:x:666:666::/home/luser:/usr/bin/rssh
With the ForceCommand, only that command is run. When you run scp or sftp, commands are run by SSH (scp, /usr/lib/openssh/sftp-server, respectively), and of course they can't be run unless the program executed by ForceCommand uses SSH_ORIGINAL_COMMAND to do so. So, for rssh to do its job, it has to be the login shell, not a ForceCommand.
Related:
Do you need a shell for SCP?
You can, instead, use a wrapper script that will use rssh instead of the login shell to execute commands. For example:
/usr/local/bin/wrapper-shell:
#! /bin/sh
rssh -c "$SSH_ORIGINAL_COMMAND"
And in /etc/ssh/sshd_config:
Match group sftponly
X11Forwarding no
AllowTcpForwarding no
ForceCommand /usr/local/bin/wrapper-shell
With /usr/local/bin/wrapper-shell being executable should work.
| Make sshd override login shell of a group of users |
1,542,878,501,000 |
I'm writing a shell script for copying a file from a remote host to a local directory using scp. In case the target directory does not exist, I'm getting a misleading error message. i.e.:
scp user@remote-host:/path/to/existing/file /local/non-existing/directory/
The error I'm getting is:
/local/non-existing/directory/: Is a directory
which is puzzling... I would expect something like:
Directory /local/non-existing/directory/ does not exist
Does it make sense to anybody or is it just me?
Do you think it is a defect in scp?
I'm running Ubuntu 14.04.3 LTS, is it the same in other operating systems?
|
Bug
Found the related bug. It seems to be fixed in Ubuntu 14.04.5 (openssh 1:6.6p1-2ubuntu2.8)
There's an explanation on a Redhat bug report :
This problem is also in original openSSH and appears when you try to
copy something into non-existing directory with existing parent
directory. There is missing check for this boundary condition. Error
message is thrown when scp process tries to write into above mentioned
file, but this file ends with slash (which is interpretation for
directory) and this is the reason for current error message.
Original answer
Cannot reproduce (tested on Ubuntu 14.04.5 LTS and Linux Mint 17)
If /local/non-existing/directory doesn't exist, scp fails with :
/local/non-existing/directory: No such file or directory
If /local/existing/directory exist, scp copies file to /local/existing/directory/file
If remote-host:/path/to/existing/file is a directory, scp fails with :
scp: file: not a regular file
Troubleshooting
ssh user@remote-host "file /path/to/existing/file"
should give you information about the remote file (or possibly directory).
file /local/non-existing/directory/
should give you information about the local directory
mkdir -p /local/non-existing/directory/
wil recursively create the directory, and any parent if necessary.
After mkdir -p, if file is really a file and /local/non-existing/directory/ is really a directory, your scp command should work.
| Copying file using scp to non-existing local directory - misleading error message |
1,542,878,501,000 |
If I want to specify for LAN addresses that I don't want to deal with host keys, how do I do that?
/etc/ssh/ssh_config
Host 192.168.*.*
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
or
UserKnownHostsFile none
even with
CheckHostIP no
Isn't doing the trick. openssh 7.1p1. With no known_hosts file in ~/.ssh or /etc, I still get:
The authenticity of host '<hostname> (192.168.2.2)' can't be established.
ECDSA key fingerprint is SHA256:.....
Are you sure you want to continue connecting (yes/no)?
This functionality was somewhat recently changed in openssh. Old questions suggest the ssh_config as shown above, which doesn't appear to work anymore.
Yes, this is a horrible idea. I want to do it anyway. It risks a man in the middle attack. It risks connecting to the wrong server if there's a configuration issue. I'm just tired of having to remove entries from known_hosts with the multiple VM's I have that often change fingerprints, and am willing to live with the risks. Yes, there's other questions like this, that explain how to do it the right way, but I don't want to do it that way. I just want to turn it off.
|
Seems like your solution on openssh mailing list seems to be quite bearable. Reposting also here:
Match exec "ping -q -c 1 -t 1 %n | grep '192\.168\.'"
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
Source: http://lists.mindrot.org/pipermail/openssh-unix-dev/2015-August/034335.html
| Disabling openssh host key checking on LAN |
1,542,878,501,000 |
Does ssh-copy-id recognize if the authorized_keys file is not in ~/.ssh? I am storing my authorized keys file in a different folder, which I have configured as:
AuthorizedKeysFile /mnt/sd_ext/.ssh/authorized_keys
But running ssh-copy-id on a client machine still causes the file to be created in ~/.ssh. Am I missing something, or is this expected behavior?
|
ssh-copy-id is actually a shell script as can be seen:
$ which ssh-copy-id
/usr/bin/ssh-copy-id
$ file /usr/bin/ssh-copy-id
/usr/bin/ssh-copy-id: POSIX shell script, ASCII text executable
It’s a fairly simple script and the .ssh/authorized_keys path is hard-coded as the script isn’t written to deal with non-standard locations for the authorized_keys file, i.e., it will always copy the keys into authorized_keys in ~/.ssh.
Sticking to convention is usually best practice but if you have a good reason for using a non-standard path, you can try editing the script to replace .ssh/authorized_keys with your own custom location.
| ssh-copy-id doesn't copy to non-default location |
1,542,878,501,000 |
I am using openSuse 12.3.
I have created a new user using:
linux-amvn:~ # useradd -m -G users,dev -s /bin/bash -p pass123 harbir-PC
The user harbir-PC is not able to login, when I try to log using ssh.
I went ahead and looked into the /etc/passwd file and I see the following:
harbir:x:1000:100:harbir:/home/harbir:/bin/bash
kdm:x:489:487:KDM Display Manager daemon:/var/lib/kdm:/bin/false
harbir-PC:x:1001:100::/home/harbir-PC:/bin/bash
There is a difference between the user harbir and harbir-PC.
I have no problem with the user harbir (who I have created during installation), but I need to login using the user harbir-PC.
I also checked the /etc/shadow, and passwords are encrypted.
|
I usually run passwd after useradd to set the password as I want it. But if you are provisioning and doing this from a script you may need to use crypt and provide the encrypted password on the command line.
| openSuse, new user cannot login |
1,542,878,501,000 |
We have encountered a security threat in one of our RHEL servers which says the SSH server is configured to use Cipher Block Chaining.
As far as I know, the RHEL systems provide security updates through their RHN satellite which can be achieved just by running the yum update command. But, how can I know if the security patch is applied to my RHEL system?
P.S: I know the CVE number of the vulnerability/threat/issue.
So my question is, is it possible for me to verify that the RHEL yum update command has fixed the bug in my system?
|
You can check this with yum-plugin-security:
--cve This option includes packages that say they fix a CVE - Common
Vulnerabilities and Exposures ID (http://cve.mitre.org/about/),
Eg. CVE-2201-0123.
So try:
yum --cve <Your CVE here> info updates
And you can check the changelog coressponding to the packages to check information about bug fixed:
$ rpm -q --changelog openssh | grep -i cve
- change default value of MaxStartups - CVE-2010-5107 - #908707
- merged cve-2007_3102 to audit patch
- fixed audit log injection problem (CVE-2007-3102)
- CVE-2006-5794 - properly detect failed key verify in monitor (#214641)
- CVE-2006-4924 - prevent DoS on deattack detector (#207957)
- CVE-2006-5051 - don't call cleanups from signal handler (#208459)
- use fork+exec instead of system in scp - CVE-2006-0225 (#168167)
| check if latest openssh patch provided by RHEL is installed |
1,542,878,501,000 |
CentOS 5.x
When I enable the Banner /path/to/banner parameter in my sshd config file, the banner displays AFTER the login as: prompt.
For example:
login as: foo
***********************************************************
Test Example SSH Banner Text
This is a test
Example 12345
***********************************************************
[email protected]'s password:
Admittedly this isn't an issue for ssh connections that connect with a username already specified prior to connecting. But for ssh connections that don't have a user name preselected, users see this upon connecting:
login as:
Is there any way to get the banner to display BEFORE the login as: prompt?
|
This is caused by your client rather than the server. The login as: prompt is PuTTY's own, and it won't display the banner before a username is entered. If you're using shared keys, then the banner will be displayed at key exchange time, even if the key goes on to be rejected.
| How can I have a SSH banner appear BEFORE the "login as:" prompt? [duplicate] |
1,542,878,501,000 |
A user (user1) on an Ubuntu 12.04 desktop has two SSH RSA keys configured: ~/.ssh/id_rsa and ~/.ssh/id_rsa1 (and .pub files). Both public keys are configured in the authorised keys on the server's account (user1@myserver).
When logged on to the desktop (client) machine, and using a Gnome Terminal, logging on to the server using either keys works fine:
ssh user1@myserver implicitly picks up /home/user1/.ssh/id_rsa
ssh -f /home/user1/.ssh/id_rsa1 user1@myserver also works.
If, instead of logging on via the Gnome Desktop, I log on to the client machine via SSH from another host (or even localhost) or use su, using /home/user1/.ssh/id_rsa no longer works.
This appears to have something to do with SSH_AUTH_SOCK (missing originally in the environment set up with an SSH connection to the client). If I set it up to be the value visible in the desktop session /tmp/keyring-xxxxxxxxxxx/ssh, logging in with id_rsa works fine again.
If I unset SSH_AUTH_SOCK (to make logging with id_rsa fail again), and copy id_rsa1 to id_rsa (and .pub files), it now works with id_rsa too.
What can explain the difference of behaviour between those two key pairs and their interaction with SSH_AUTH_SOCK?
I can't see anything in the server logs.
Here is the fragment of the SSH client logs, just before it differs:
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/user1/.ssh/id_rsa (0x7f6b7059b260)
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred gssapi-keyex,gssapi-with-mic,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/user1/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
Followed by this, when it doesn't work for that user/key:
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method
|
It turns out that the key that didn't work wasn't configured properly in the authorized_keys file after all. Sorry about that...
I wrongly assumed that ssh -i /home/user1/.ssh/id_rsa user1@myserver was an indication that it was configured properly, but this turns out not to be the case. It makes use of other keys too. Forcing ssh -i /home/user1/.ssh/id_rsa -oIdentitiesOnly=yes user1@myserver makes it fail with the incorrect configuration too.
I guess the SSH agent set up when logging on with Gnome also picks up other keys in the ~/.ssh/ directory, which makes it work with that other key, even if the wrong key is specified with -i.
| SSH public key login: two different keys and SSH_AUTH_SOCK behaviour |
1,542,878,501,000 |
I installed openssh via brew install openssh.
I added the following to my .profile:
export SSH_AUTH_SOCK="~/.ssh/agent.$HOST.sock"
ssh-add -l 2>/dev/null >/dev/null
if [ $? -ge 2 ]; then
ssh-agent -a "$SSH_AUTH_SOCK" >/dev/null
fi
And then I have to do the following:
ssh-add ~/.ssh/id_ecdsa_sk
Enter passphrase for /Users/myuser/.ssh/id_ecdsa_sk:
Identity added: /Users/myuser/.ssh/id_ecdsa_sk
even though I have the following in my ~/.ssh/config:
Host *
IgnoreUnknown UseKeychain
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ecdsa_sk
(I had to add the IgnoreUnknown bit b/c the install from brew installs a version that breaks the UseKeychain bit.) But now: how do I wire it up so it adds the key to my keychain?
Help appreciated!
|
Keychain integration is a feature added by Apple that is not in the standard release of OpenSSH. As you have now installed the standard OpenSSH release from HomeBrew, you won't have this functionality anymore. You have discovered this as the UseKeychain option now gives configuration errors - adding the IgnoreUnknown configuration only makes the error message go away, it won't actually bring back any functionality.
In order to get Keychain integration, you will want to uninstall the HomeBrew version of OpenSSH and use the version supplied by Apple.
The version in HomeBrew will not for the foreseeable future have Keychain integration - it's not that they can't make it work at all, but rather that they have found the implementation that was made to be too big a risk for the project, as it's a big change that doesn't come from the OpenSSH project itself. You can read about that discussion here.
If you look at the link, you'll see that you can still download the old patch, and try that out if you like. However, as it is no longer maintained, it is a security risk.
Similarly you can download a third party mod to add Keychain support here. However that hasn't been updated since 2017 it seems, and as such would also be a security risk.
| MacOS: Installed openssh via brew, how do I add keys to keychain? |
1,542,878,501,000 |
The setup:
Raspberry 3B running Raspbian Stretch 9 on an external HDD and using ZRAM
Raspi used as a webserver running LAMP and MERN stacks and accessed remotely via SSH with 1 IDE (Coda for Mac OS)
SSH port forwarded by router with static IP
fail2ban running
The problem:
When accessing the raspberry from a remote location (over the Internet) via SSH, it works until the connection hangs. This occurs randomly.
I can sometimes SSH it again after few minutes, and sometimes not until I restart the Raspi.
What I've tried:
SSH in verbose mode from remote location:
debug1: Local version string SSH-2.0-OpenSSH_8.1
kex_exchange_identification: read: Connection reset by peer
SSH in verbose mode from local network (I actually SSH another machine on the local network remotely, then SSH the Raspi from that machine). Same result: Connection reset by peer
Checked /etc/hosts.allow and /etc/hosts.deny => Nothing there
Checked iptables via iptables -L --line-number => Nothing there
Checked logs: /var/log/fail2ban.log and sudo journalctl -t sshd => Nothing striking there
Updated sshd_config with no DNS
Re-installed SSH via apt-get --reinstall install openssh-server openssh-client
I am running out of ideas here and no clue about what's happening.
As someone encountered the same problem with SSH connection before ?
Could it be a load issue on the raspberry ?
|
Long story short, my problem had nothing to do with a network issue and was fixed by examining the syslog.
In details:
I noticed that none of the webapps (via LAMP or MERN stacks) while up and running before the issue started, were not reachable anymore.
So I dug up the syslog with the tail -f -n X /var/log/syslog command (replacing X with the number of lines you want to display).
I then noticed few lines mentioning a Voltage problem (sorry I did keep the exact terms). But basically it meant that my Raspi which an external HDD was plugged on did not have a strong enough power supply.
Then it looked that the HDD was unmounted and the system crashed, which explains all the issues mentioned above.
So I removed the HDD put the SD card back and ran the Raspi again while going through the syslog again and monitoring the memory with htop. It turned out that when I started both the apache and node servers, the RAM and SWAP memories were getting full repeating the same consequences mentioned above.
So finally I increased the SWAP memory by using ZRAM. Link here .
Now everything runs well but still monitoring.
| SSH "kex_exchange_identification: read: Connection reset by peer" |
1,542,878,501,000 |
I want to install openssh-server on my server, but it shows me :
apt-get install openssh-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
openssh-server is already the newest version.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
upstart : Depends: ifupdown (>= 0.6.10ubuntu5)
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
when I try to apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
python-numpy python-gobject-2 python-gobject-dev libpython2.7 docbook-xml
docbook-xsl python-dev libgirepository-1.0-1 liblapack3gf libffi-dev
libquadmath0 libffi5 python-gi libssl-dev python2.6-dev libglade2-0
libblas3gf gir1.2-glib-2.0 python-gobject sgml-data libgfortran3
python2.7-dev
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
ifupdown
Suggested packages:
ppp rdnssd
The following packages will be upgraded:
ifupdown
1 upgraded, 0 newly installed, 0 to remove and 325 not upgraded.
9 not fully installed or removed.
Need to get 0 B/48.3 kB of archives.
After this operation, 43.0 kB disk space will be freed.
Do you want to continue [Y/n]? y
y
Reading changelogs... Done
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
dpkg: dependency problems prevent configuration of plymouth:
plymouth depends on upstart-job; however:
Package upstart-job is not installed.
Package upstart which provides upstart-job is not configured yet.
plymouth depends on udev (>= 166-0ubuntu4); however:
Package udev is not configured yet.
dpkg: error processing plymouth (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of mountall:
mountall depends on udev; however:
Package udev is not configured yet.
mountall depends on plymouth; however:
Package plymouth is not configured yet.
dpkg: error processing mountall (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of initscripts:
initscripts depends on upstart; however:
Package upstart is not configured yet.
initscripts depends on mountall (>= 2.28); however:
Package mountall is not configured yet.
dpkg: error processing initscripts (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
No apport report written because the error message indicates its a followup error from a previous failure.
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
plymouth
mountall
initscripts
E: Sub-process /usr/bin/dpkg returned an error code (1)
so I tried to install deb files with dpkg -i --force-overwrite
but again shows me error.
lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 6.0.10 (squeeze)
Release: 6.0.10
Codename: squeeze
apt-cache policy
Package files:
100 /var/lib/dpkg/status
release a=now
500 http://ftp.debian.org/debian/ jessie-backports/main Translation-en
100 http://ftp.debian.org/debian/ jessie-backports/main i386 Packages
release o=Debian Backports,a=jessie-backports,n=jessie-backports,l=Debian Backports,c=main
origin ftp.debian.org
100 http://ftp.debian.org/debian/ jessie-backports/main amd64 Packages
release o=Debian Backports,a=jessie-backports,n=jessie-backports,l=Debian Backports,c=main
origin ftp.debian.org
500 http://deb.debian.org/debian-security/ stable/updates/main Translation-en
500 http://deb.debian.org/debian-security/ stable/updates/main i386 Packages
release v=8,o=Debian,a=stable,n=jessie,l=Debian-Security,c=main
origin deb.debian.org
500 http://deb.debian.org/debian-security/ stable/updates/main amd64 Packages
release v=8,o=Debian,a=stable,n=jessie,l=Debian-Security,c=main
origin deb.debian.org
500 http://deb.debian.org/debian/ stable-updates/non-free Translation-en
500 http://deb.debian.org/debian/ stable-updates/main Translation-en
500 http://deb.debian.org/debian/ stable-updates/contrib Translation-en
500 http://deb.debian.org/debian/ stable-updates/non-free i386 Packages
release o=Debian,a=stable-updates,n=jessie-updates,l=Debian,c=non-free
origin deb.debian.org
500 http://deb.debian.org/debian/ stable-updates/contrib i386 Packages
release o=Debian,a=stable-updates,n=jessie-updates,l=Debian,c=contrib
origin deb.debian.org
500 http://deb.debian.org/debian/ stable-updates/main i386 Packages
release o=Debian,a=stable-updates,n=jessie-updates,l=Debian,c=main
origin deb.debian.org
500 http://deb.debian.org/debian/ stable-updates/non-free amd64 Packages
release o=Debian,a=stable-updates,n=jessie-updates,l=Debian,c=non-free
origin deb.debian.org
500 http://deb.debian.org/debian/ stable-updates/contrib amd64 Packages
release o=Debian,a=stable-updates,n=jessie-updates,l=Debian,c=contrib
origin deb.debian.org
500 http://deb.debian.org/debian/ stable-updates/main amd64 Packages
release o=Debian,a=stable-updates,n=jessie-updates,l=Debian,c=main
origin deb.debian.org
500 http://deb.debian.org/debian/ stable/non-free Translation-en
500 http://deb.debian.org/debian/ stable/main Translation-fr
500 http://deb.debian.org/debian/ stable/main Translation-en
500 http://deb.debian.org/debian/ stable/contrib Translation-en
500 http://deb.debian.org/debian/ stable/non-free i386 Packages
release v=8.8,o=Debian,a=stable,n=jessie,l=Debian,c=non-free
origin deb.debian.org
500 http://deb.debian.org/debian/ stable/contrib i386 Packages
release v=8.8,o=Debian,a=stable,n=jessie,l=Debian,c=contrib
origin deb.debian.org
500 http://deb.debian.org/debian/ stable/main i386 Packages
release v=8.8,o=Debian,a=stable,n=jessie,l=Debian,c=main
origin deb.debian.org
500 http://deb.debian.org/debian/ stable/non-free amd64 Packages
release v=8.8,o=Debian,a=stable,n=jessie,l=Debian,c=non-free
origin deb.debian.org
500 http://deb.debian.org/debian/ stable/contrib amd64 Packages
release v=8.8,o=Debian,a=stable,n=jessie,l=Debian,c=contrib
origin deb.debian.org
500 http://deb.debian.org/debian/ stable/main amd64 Packages
release v=8.8,o=Debian,a=stable,n=jessie,l=Debian,c=main
origin deb.debian.org
Pinned packages:
any idea ?
|
You may want to try purging the installation and cleaning up apt a bit.
Try:
sudo apt-get remove openssh-server openssh-client --purge && sudo apt-get autoremove && sudo apt-get autoclean && sudo apt-get update
If you don't have any reason not to upgrade packages then also try:
sudo apt-get dist-upgrade
You can then try installing the packages again to see if this resolved the issue:
sudo apt-get install openssh-server openssh-client
Edit:
Noticed that ubuntu is referenced in the error: upstart : Depends: ifupdown (>= 0.6.10ubuntu5)
Check your sources.list file and sources.list.d directory files for any references to ubuntu. If there are comment them out and try the above commands again.
If any ubuntu PPA's or ubuntu .deb packages are installed this could also cause issues.
| How to install openssh-server on my server? |
1,542,878,501,000 |
OpenSSH's display format for host key fingerprints has changed recently - between versions 6.7 and 6.8. When connecting to a new host, the message now looks like this:
user@desktop:~$ ssh 10.33.1.114
The authenticity of host '10.33.1.114 (10.33.1.114)' can't be established.
ECDSA key fingerprint is SHA256:9ZTSzJsnk0byQRs24iKoYrf/d5eDvQL60tR/zO41k/I.
Are you sure you want to continue connecting (yes/no)?
On the remote host server (which I reached through a 3rd machine, where I had accepted the key earlier using an older client), I can see the fingerprint with
user@server:~$ ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key
256 a2:7e:2b:87:4c:47:69:16:78:9e:1a:4b:db:a7:a2:57 root@server (ECDSA)
But there's no way to match these two up.
If I install an older ssh version on desktop, and first connect using that, I see
user@desktop:~$ ssh 10.33.1.114
The authenticity of host '10.33.1.114 (10.33.1.114)' can't be established.
ECDSA key fingerprint is a2:7e:2b:87:4c:47:69:16:78:9e:1a:4b:db:a7:a2:57.
Are you sure you want to continue connecting (yes/no)?
That matches, so I can safely accept it, and it gets added to my ~/.ssh/known_hosts. Then the newer version of ssh also accepts it. But that requires me to build/install the older ssh version on desktop.
From an answer to another question about server fingerprints, I learned that the old form can be shown with ssh-keygen -E md5, and the new one is -E sha256. But the -E option only appeared when SHA256 became the default - the version of ssh-keygen on server can only show MD5. To see the SHA256 fingerprint of the key I trust, I'd first have to retrieve it (eg. through that 3rd machine) and put it where the newer ssh-keygen can find it. Or I'd have to run a newer ssh-keygen on server. (-E means something completely different for ssh.)
How can I display both keys (the one that I trust, and the one that I'm being presented with) in the same format? Preferably without installing additional versions, or copying key files around?
|
Use
ssh -o FingerprintHash=md5 10.33.1.114
to get the old-md5 fingerprint from the client.
| Verify host key fingerprint in old format |
1,542,878,501,000 |
I am using OpenSSH chrootdirectory feature to give access to a user via ssh.
Can this user exit the jail and return to the normal OS environment? Maybe with su?
|
If the user does not have root access (or any way to gain it, such as exploiting an insecure setuid program), escaping a chroot jail should be impossible.
With root access, escaping a chroot jail is trivial. In fact, the chroot(2) manpage even gives instructions:
This call does not change the current working directory, so that after
the call '.' can be outside the tree rooted at '/'. In particular, the
superuser can escape from a "chroot jail" by doing:
mkdir foo; chroot foo; cd ..
| Chroot user exit jail [duplicate] |
1,542,878,501,000 |
In Crux Linux I already have installed SSH but when I use ssh-keygen, and try to use the command:
ssh localhost
to test SSH I get this error:
# ssh localhost
ssh: connect to host localhost port 22: Connection refused
#
So I decided to reinstall openssh but without apt-get I don't know how to do that.
|
You have the client (and, I believe, also the server) installed. But you're not running the server on your machine (it's not started by default on Crux).
Add sshd to the SERVICES setting in /etc/rc.conf. See the handbook. This will take care of starting the SSH server at boot time. For now, run /etc/rc.d/sshd start.
As per the FAQ, you may want to customize /etc/hosts.allow or /etc/hosts.deny first. Note that these files offer hostname-based protection, which is not always trivial to circumvent but far from absolute nonetheless. Ssh itself provides good protection against intruders (as long as you don't enable passwords, or make sure every user has a high-entropy password), so I recommend allowing SSH access to all (sshd: ALL in /etc/hosts.allow).
| How to install openssh in Crux Linux |
1,542,878,501,000 |
Is this even possible or is there a bug with openssh?
I had a problem with a compiler, and to allow the compiler's developer to replicate the result I created a remote server. The crazy thing is me running the same command on the same remote machine with the same user resulted in a different output than his. What could be the cause of this?
So in short, I get a failure when running ssh root@remote_machine 'command' and another person runs the command successfully, even though the remote_machine is the same. This is extremely baffling, how could this be?
It also happens when I run this command interactively in ssh session.
When I run it from my local machine, it fails:
[efe@efeninki ~]$ ssh [email protected]
[email protected]'s password:
[root@vultr ~]# cd test/
[root@vultr test]# ls
Address.sol solc-linux-amd64-v0.8.10+commit.fc410830 test.sh
[root@vultr test]# ./solc-linux-amd64-v0.8.10+commit.fc410830 --bin Address.sol
Error: Function "extcodesize" not found.
--> Address.sol:34:21:
|
34 | size := extcodesize(account)
| ^^^^^^^^^^^
Error: Variable count for assignment to "size" does not match number of values (1 vs. 0)
--> Address.sol:34:13:
|
34 | size := extcodesize(account)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When the other user runs it from a docker instance, it succeeds:
[efe@efeninki ~]$ sudo docker run -it --rm ubuntu bash
root@437d7edb92fc:/# ssh [email protected]
[email protected]'s password:
[root@vultr ~]# cd test/
[root@vultr test]# ls
Address.sol solc-linux-amd64-v0.8.10+commit.fc410830 test.sh
[root@vultr test]# ./solc-linux-amd64-v0.8.10+commit.fc410830 --bin Address.sol
======= Address.sol:Address =======
Binary:
60566050600b82828239805160001a6073146043577f4e487b7100000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220ebf580f669e9f89d1faea352d4ba1d4ab2d9c9774fda9fb483588d4e9b09eb5564736f6c634300080a0033
|
ssh has an option to transfer some environment variables from the client to the host (SendEnv on the client side ssh, AcceptEnv on the server side sshd). It might be that some environment variables you have on the client side are transferred to the server which causes this problem, and the other user doesn't (or has different configuration in his ssh_config).
You should compare the environment in the ssh between you and the other user:
ssh root@remote_machine 'env'
My guess is that you'll see some differences that might impact the different results.
| Same ssh command gives different results to different local machines |
1,542,878,501,000 |
Given the following ssh.cfg:
Host bastion
Hostname xx.yyy.169.100
User ubuntu
IdentityFile ./the-key.pem
Host 10.250.*.*
ProxyJump %r@bastion
User core
IdentityFile ./the-key.pem
The attempt to connect to the server via the bastion is failing, because ssh applies wrong username:
$ ssh -vvF ssh.cfg 10.250.198.76
...
debug1: Reading configuration data ssh.cfg
debug1: ssh.cfg line 1: Applying options for bastion
debug2: resolve_canonicalize: hostname xx.yyy.169.100 is address
debug2: ssh_connect_direct
debug1: Connecting to xx.yyy.169.100 [xx.yyy.169.100] port 22.
debug1: Connection established.
debug1: identity file ./the-key.pem type -1
debug1: identity file ./the-key.pem-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to xx.yyy.169.100:22 as 'core'
...
I expected that ssh will apply the ubuntu user when it's connecting to the bastion and will only apply core user when it's connecting to the target server.
Is there a way to configure it the way I want?
|
The %r part of your ProxyJump entry is being substituted for the username of the remote machine you are currently trying to ssh into (core). You just need:
ProxyJump bastion
so that it uses the default username for your bastion entry. See the OpenSSH Cookbook for more information.
| SSH ProxyJump applies wrong username |
1,542,878,501,000 |
I keep a local git repo at a remote host gitserver deployed to my LAN. When I am away from home I have to access that server through the LAN's external IP. (The router does not offer loopback).
At home my LAN DNS resolves gitserver to the LAN address but when I'm away, I put gitserver to my /etc/hosts file as the external IP of the LAN.
This works well enough for me but I get a warning that the external IP is not in the known_hosts file.
I'm trying to add that key using ssh-keyscan
ssh-keyscan -p 4444 -t ecdsa 100.101.102.103
I get a result like :
[100.101.102.103]:4444 ecdsa-sha2-nistp256 <GOBBLEDEEGOOKalphanumericstring>
I want to update my known_hosts file with that key but the known_hosts file expects what I suspect is a hostID key. For example:
|1|SoMeThing=|AnotherThing= ecdsa-sha2-nistp256 = ecdsa-sha2-nistp256 <GOBBLEDEEGOOKalphanumericstring>
How do I find the SoMeThing... part -- the HostID? -- of the known_hosts entry?
|
The |1|b64|b64 format in ~/.ssh/known_hosts is a hashed hostname; see HashKnownHosts in man 5 ssh_config and -H in man 1 ssh-keygen. Using this format is optional; if you want it, see -H in man 1 ssh-keyscan
Note that if anyone intercepts your first connection from a given machine to what you think is the correct address (your 100.101.102.103) they can supply a fake key and steal and/or alter the data you send and receive on that machine.
| SSH add key to known_hosts from ssh-keyscan |
1,542,878,501,000 |
I have an issue where my server is not able to ssh to a cisco device after upgrading the server to the latest version.
I did a ssh -vvv, I am not sure about two sections. Below are the details :
I want to know the meaning of ciphers ctos and ciphers stoc
ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
Also at the end of the log, got info :
Unable to negotiate with 10.44.39.202 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
Is it okay to add diffie-hellman-group1-sha1 to the host key algorithms?
The below is the debug log :
-bash-4.0# ssh -vvv 10.44.39.202 OpenSSH_7.7p1, OpenSSL 1.0.2j-fips 26 Sep 2016
debug1: Reading configuration data /usr/etc/ssh_config
debug2: resolve_canonicalize: hostname 10.44.39.202 is address
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 10.44.39.202 [10.44.39.202] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.7
debug1: Remote protocol version 2.0, remote software version Cisco-1.25
debug1: match: Cisco-1.25 pat Cisco-1.* compat 0x60000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 10.44.39.202:22 as 'root'
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: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-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: diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-rsa
debug2: ciphers ctos: aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc
debug2: ciphers stoc: aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc
debug2: MACs ctos: hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96
debug2: MACs stoc: hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96
debug2: compression ctos: none
debug2: compression stoc: none
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: (no match)
Unable to negotiate with 10.44.39.202 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
|
Your upgraded OpenSSH no longer includes diffie-hellman-group1-sha1 as a key exchange algorithm by default, yet that's the only key exchange algorithm that the Cisco device is offering.
The quickest work-around would be to tell your SSH client that it's OK to use diffie-hellman-group1-sha1 in communication with that device. Add a stanza to your ~/.ssh/config like this:
Host 10.44.39.202
KexAlgorithms +diffie-hellman-group1-sha1
Reference:
OpenSSH legacy options:
If the client and server are unable to agree on a mutual set of parameters then the connection will fail. OpenSSH (7.0 and greater) will produce an error message like this:
Unable to negotiate with legacyhost: no matching key exchange method found.
Their offer: diffie-hellman-group1-sha1
| ssh to Cisco device not working [duplicate] |
1,542,878,501,000 |
Is there an easy way to generate hashed hostnames to be added to the ~/.ssh/known_hosts file?
I'd like to add a @cert-authority line to the ~/.ssh/known_hosts file.
Obviously the ssh-keygen command would not get the CA cert.
I think it also needs a connection to the server,
and I'm not sure I can get it to hash a wildcard.
So, how would I hash "*.bar.com", for example,
so that it can be used in the ~/.ssh/known_hosts file?
Edit: Having thought about it, hashed wildcards probably can't work, as it would be too difficult for the client to match a wildcard after it has been hashed. But, if I can still get a method to hash a domain without requiring a connection to the server (as ssh-keygen does), that would be great.
|
If you want to change the hostname for an existing hashed host, edit your known_hosts file, replacing the hashed hostname with the plaintext hostname you wish associated with that key, and rehash the file:
ssh-keygen -H
If you want to generate hashes for a list of hostnames without disturbing your known_hosts, create a file combining the hostnames you wish to hash with a valid key copied out of an existing known_hosts :
sample.bar.com ecdsa-sha2-nistp256 AAAAE2...
other.bar.com ecdsa-sha2-nistp256 AAAAE2...
diff.domain.org ecdsa-sha2-nistp256 AAAAE2...
Then hash this file using ssh-keygen :
ssh-keygen -f mytestfile -H
| Generate hashed name for SSH known_hosts |
1,542,878,501,000 |
What is a good configuration to allow ssh root access in order to set up your server? Most of the time I have the connection closed but maintenance and setup requires as such.
I've been using the same configuration for the past 15 years; FreeBSD mostly.
|
Don't allow SSH root access on your server. Allow only a small subset of nonprivileged users; have them added to the sudoers file so they can sudo root.
Here's an example of what you should have on your /etc/ssh/sshd_config:
PermitRootLogin no
AllowUsers ahr 13nilux dr01
If you disable password-based authentication and allow only pubkey authentication to your server, it's even better.
| SSH root access configuration |
1,542,878,501,000 |
How to log the Protocol, KexAlgorithm, Cipher and MAC algorithm negociated by the client and the client's user agent string?
What I'm looking for is the OpenSSH equivalent to Apache HTTPD's CustomLog+LogFormat+mod_ssl %{SSL_PROTOCOL}x %{SSL_CIPHER}x + %{User-agent}i
I want to log (on the server side) the same information that are availiable on the client side :
$ ssh -v localhost 2>&1 |grep kex
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
+
$ ssh -v localhost 2>&1 |grep version
debug1: Local version string SSH-2.0-OpenSSH_6.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.7
|
Use at least LogLevel DEBUG to see these message in the server log. Also do not forget to restart the sshd service after the change.
sshd[31049]: debug1: Client protocol version 2.0; client software version OpenSSH_6.0p1 Debian-4+deb7u3
sshd[31049]: debug1: kex: client->server aes128-ctr hmac-md5 none [preauth]
sshd[31049]: debug1: kex: server->client aes128-ctr hmac-md5 none [preauth]
If you mean SSH client version by the "user agent".
Also note that there will be a lot of more information in the logs. If you use RHEL/Fedora, these information should be already in the audit log (except the client software version).
| OpenSSH accesslog : Logging ciphers, MAC and user agent |
1,542,878,501,000 |
I'm using a new system and ssh is ignoring my ssh-agent. Note I've been doing this for years elsewhere, it is not a new thing I am confused about. With bash:
> echo $SSH_AGENT_PID
1234
> echo $SSH_AUTH_SOCK
/tmp/ssh-foo/agent.1234
> ps -p 1234
PID TTY TIME CMD
1234 pts/12 00:00:01 ssh-agent
So, ssh-agent is clearly running and the appropriate environment variables are in place. I've also verified the socket is actually there.
> ssh-add key
Enter passphrase for key: [done]
Identity successfully added.
> ssh-add -l
1024 SHA256:[blah] key
So the key has been added. But:
> ssh -i key me@there
Enter passphrase for key:
PARDON?
I've diff'd /etc/ssh/ssh_config with one from my previous system (!#$% upgrading...) and they are identical. According to the distro (fedora 23) package meta-info this one is openSSH version 7.1p1, previous installs I've used are no newer than 6.6.
The problem doesn't exist for all users, leading me to believe it might be some new security feature. Does anyone know what's up?
|
It is a new feature, presumably for 7.x. It required adding the key type to /etc/ssh_config using this option:
PubkeyAcceptedKeyTypes +ssh-dss
RSA keys are accepted by default (see man ssh_config), which is why it worked in one case but not another (being root was a red herring factor and I've removed this from the question).
Note again that option is not in my previous ssh_config nor in the corresponding man page (openssh v. 6.6).
| ssh ignores ssh-agent |
1,542,878,501,000 |
Used for a few years arcfour as default cipher for SSH2 connection in my ~/.ssh/config file
host namaka
hostname localhost
port 2022
ciphers arcfour
IdentityFile ~/.ssh/virtualbox
compression true
StrictHostKeyChecking no
user kermit
After an upgrade to Debian 8 I have discovered this cipher has been disabled from default ssh configuration and I was getting the following error
no matching cipher found: client arcfour server aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],[email protected]
So I changed my ~/.ssh/config to
host namaka
hostname localhost
port 2022
ciphers aes256-ctr
IdentityFile ~/.ssh/virtualbox
compression true
StrictHostKeyChecking no
user kermit
(notice the cipher aes256) and now my ssh connection are working again.
kermit@euroforce:~$ ssh kermit@namaka
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Jul 16 00:20:21 2015 from 10.0.2.2
kermit@namaka:~$
Unfortunately I am still getting the no matching cipher error when I try to do an scp
kermit@euroforce:~$ scp foo kermit@namaka:/tmp/
no matching cipher found: client arcfour server aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],[email protected]
lost connection
It seems scp has cached somewhere the previous cipher and does not want to use the new one.
Forcing the cipher from command line does work
kermit@euroforce:~$ scp -c aes256-ctr foo kermit@namaka:/tmp/foo2
foo 100% 0 0.0KB/s 00:00
Forcing the config file does not work
kermit@euroforce:~$ scp -C .ssh/config foo kermit@namaka:/tmp/foo2
no matching cipher found: client arcfour server aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],[email protected]
lost connection
Any clue?
|
I've found the culprit: it was a bash alias I created a few years ago and then forgot
alias scp='scp -c arcfour'
Shame on me
| scp does not honor .ssh/config |
1,542,878,501,000 |
Our accounts in our lab are all mounted over NFS and are accessible over all the systems in a subnet. So, effectively we can ssh into any of the machines in the subnet and continue our work. The problem is that the machines come up or go down randomly because of people accidently turning it off etc. To find running machines I scan the subnet using nmap and choose a machine.
Because of the above problem, I can't put a fixed entry for Hostname in my ssh config entry. So, how can I have an ssh config entry that will have all other parameters except Hostname such that the ssh config entry and the Hostname can somehow be given together while running ssh?
|
The Host directive can take multiple hosts, for example:
Host *.domain.tld specific-host.tld 10.*.*.*
User foo
Port 2222
This would set user and port for all hosts matching the star pattern,
the explicit host specific-host.tld, or, assuming you type IP
numbers, any host whose first IPv4 byte is 10. Then you can add Host
/ HostName pairs to give nicknames to specific hosts, for example.
| Use a dynamically obtained hostname with an ssh config entry |
1,542,878,501,000 |
I am not sure what's causing this, but it's mildly frustrating.
I'm sshing into my machine (Ubuntu 21.10) and invoking a tilix session to my client machine. I trying to run an app (from within tilix remotely), I need to run which should prompt for a password. The machine is running a GUI (kded5), but that shouldn't matter. I'm ssh'ed into the machine. This app prompts for password in the GUI instead of in the terminal.
I've tried unsetting DISPLAY. I've tried setting SSH_ASKPASS_REQUIRE=never (used them separately and together). I've tried various other things but to no avail. Since I'm using kded5, the system alternatives is set to /usr/bin/kshaskpass. I haven't tried setting it to something else:
at 14:25:06 ❯ update-alternatives --display ssh-askpass
ssh-askpass - auto mode
link best version is /usr/bin/ksshaskpass
link currently points to /usr/bin/ksshaskpass
link ssh-askpass is /usr/bin/ssh-askpass
slave ssh-askpass.1.gz is /usr/share/man/man1/ssh-askpass.1.gz
/usr/bin/ksshaskpass - priority 35
slave ssh-askpass.1.gz: /usr/share/man/man1/ksshaskpass.1.gz
/usr/lib/ssh/x11-ssh-askpass - priority 10
slave ssh-askpass.1.gz: /usr/share/man/man1/x11-ssh-askpass.1x.gz
To be clear, what I want is simple...
if I'm the terminal to the machine, use the terminal to prompt for passwords. If I'm in the GUI, use the GUI or at least point me in the direction on how to temporarily use terminal prompting if so desired.
TIA!
|
Well it's not perfect, but I had to settle for the hints here...
The problem was mainly stemming from my signing code to github, which when I attempted to commit code, a dialog box was being created in my GUI, but I couldn't or wasn't seeing that from my Xserver. It was popping it up off-screen. So I needed to force console password entry. I finally found this hinting that gpg-agent was the culprit for asking for the password. So, I tweaked my $HOME/.gnupg/gpg-agent.conf, which I had to create as it did not exist, yet. In the link, the option is there to use pinentry-curses, which I already have installed. Finally, issuing the command gpg-connect-agent reloadagent /bye and re-committing my code confirmed my issue was fixed. I hope this helps someone else. It's not perfect, but it gets me what I was desiring.
| Force password prompt to work in terminal instead of GUI |
1,542,878,501,000 |
I'd like to configure an SSH Daemon on one of my servers so that certain users on remote clients can execute certain commands on the server. Each user, identified by a certain public key, must be able to execute a command specific to him.
In general, there seem to be many options to do this, three of them being:
ForceCommand ... in sshd_config: This is not flexible enough in my case since each of those users (public keys) should trigger another command.
command="..." in authorized_keys: This is ideally suited for my situation since each user has an individual authorized_keys file in his home directory on that server and thus each user can execute his own, individual command. But I have an understanding problem with that method which leads me to the question detailed below.
The /usr/lib/restricted-ssh-commands method: This method is a little bit oversized for my use case because each of my users needs only one command to execute; furthermore, the regular expressions which are used with this method must be crafted very carefully, because they impose a security risk otherwise.
As noted above, I would like to opt for second method. However, in every tutorial I have read (and that was a lot, e.g. this one) it was stressed that we should add not only the command=... option in the authorized_keys files, but several more, like so:
command="/bin/foo bar baz",no-port-forwarding,no-x11-forwarding,no-agent-forwarding ssh-rsa ...
Now I am worried about the relationship between /etc/ssh/sshd_config (where I already have configured all daemon options which are important to me system-wide) and the options in the authorized_keys files.
I have read man authorized_keys which gave me the impression that authorized_keys takes precedence over sshd_config for the options which are in both of them. However, it isn't clearly stated (unless I have missed it) what happens with the options which are not in authorized_keys, but are in sshd_config; will they be taken from sshd_config?
To give a real example: no-x11-forwarding is one of the options we can (and should, according to all tutorials I have read) use in authorized_keys. But I already have X11Forwarding no in sshd_config. So what happens if I leave no-x11-forwarding away from authorized_keys?
Having to include all relevant options in each authorized_keys file would be a little dumb IMHO, but once again, every tutorial I have come across stressed that we should do it.
I would be grateful if somebody could shed some light on this.
|
If you use a recent enough openssh server (>= version 7.2), then you get the option restrict in the authorized_keys file:
restrict
Enable all restrictions, i.e. disable port, agent and X11 forwarding, as well as
disabling PTY allocation and execution of
~/.ssh/rc. If any future restriction capabilities are added to
authorized_keys files they will be included in this set.
then you can be assured that all possible restrictions apply, and will still apply in the future. Depending on needs, you might have to add additional enabling parameters after restrict (example: pty for interactive usage).
| Relationship between options in authorized_keys and options in sshd_config? |
1,542,878,501,000 |
When I try to use up-arrow command history via sftp to my CentOS 7 server it just prints ASCII characters to the output instead of recalling recent commands:
sftp> ^[[A
It's very time consuming and annoying to have to retype commands all the time. Is there also a way to enable something similar to bash-completion?
|
Credit to @steeldriver who pointed out libedit is needed. So it was simply a matter of adding the libedit USE flag for portage. I added it locally like so:
# /etc/portage/package.use
>=net-misc/openssh-7.7_p1-r9 libedit
And then rebuilt OpenSSH:
$ emerge -av net-misc/openssh
Additionally, this requires bash-completion to already be installed and enabled for sftp.
Install bash completion:
$ sudo emerge --ask app-shells/bash-completion
You can check bash-completion is enabled for sftp like this:
$ eselect bashcomp list | grep ftp
Which should return somthing like:
[337] lftp *
[338] lftpget *
[451] ncftp *
[633] sftp *
The trailing asterisk confirms bash-completion is enabled for sftp, (and in this case, several other ftp utils also).
| How to enable up-arrow command history and command completion in sftp on Gentoo? |
1,542,878,501,000 |
I would like to login to 127.0.0.1 via SSH without using a public key and password. sshd_config and log files are provided below, so here's just a quick outline:
The user accounts password is deleted with passwd --delete, i. e. login is possible without password
PasswordAuthentication and PermitEmptyPasswords is generally set to no, but is set to yes for logins from 127.0.0.0/8 via Match condition. Logs indicate the Match condition was parsed correctly and is met.
Logs suggest that it is PAM which is getting in the way.
I already did quite a bit of research, but PAM seems to be a very complex topic. I did not yet understand how SSH and PAM are interconnected.
I'm running Linux manuel-nas 4.9.0-6-amd64 #1 SMP Debian 4.9.82-1+deb9u3 (2018-03-02) x86_64 GNU/Linux
Logs and configuration files:
sshd_config:
# $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here! PasswordAuthentication no
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads) ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'. UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed ClientAliveInterval 0 ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Allow client to pass locale environment variables AcceptEnv LANG LC_*
# override default of no subsystems Subsystem sftp /usr/lib/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
Match Address 127.0.0.0/8
PasswordAuthentication yes
PermitEmptyPasswords yes
Match user diskuser
ForceCommand internal-sftp
ChrootDirectory /mnt/daten
Match user diskuser-privat
ForceCommand internal-sftp
ChrootDirectory /mnt/privat
sshd debug output:
$ /usr/sbin/sshd -p2222 -ddd
--- Beginning stripped for clarity ---
debug3: checking match for 'Address 127.0.0.0/8' user user host 127.0.0.1 addr 127.0.0.1 laddr 127.0.0.1 lport 2222
debug1: connection from 127.0.0.1 matched 'Address 127.0.0.0/8' at line 125
debug3: match found
debug3: reprocess config:126 setting PasswordAuthentication yes
debug3: reprocess config:127 setting PermitEmptyPasswords yes
debug3: checking match for 'user diskuser' user user host 127.0.0.1 addr 127.0.0.1 laddr 127.0.0.1 lport 2222
debug3: match not found
debug3: checking match for 'user diskuser-privat' user user host 127.0.0.1 addr 127.0.0.1 laddr 127.0.0.1 lport 2222
debug3: match not found
debug3: mm_answer_pwnamallow: sending MONITOR_ANS_PWNAM: 1
debug3: mm_request_send entering: type 9
debug2: monitor_read: 8 used once, disabling now
debug3: mm_getpwnamallow: waiting for MONITOR_ANS_PWNAM [preauth]
debug3: mm_request_receive_expect entering: type 9 [preauth]
debug3: mm_request_receive entering [preauth]
debug2: input_userauth_request: setting up authctxt for user [preauth]
debug3: mm_start_pam entering [preauth]
debug3: mm_request_send entering: type 100 [preauth]
debug3: mm_inform_authserv entering [preauth]
debug3: mm_request_send entering: type 4 [preauth]
debug3: mm_request_receive entering
debug3: monitor_read: checking request 100
debug1: PAM: initializing for "user"
debug1: PAM: setting PAM_RHOST to "127.0.0.1"
debug1: PAM: setting PAM_TTY to "ssh"
debug2: monitor_read: 100 used once, disabling now
debug2: input_userauth_request: try method none [preauth]
debug3: mm_auth_password entering [preauth]
debug3: mm_request_send entering: type 12 [preauth]
debug3: mm_auth_password: waiting for MONITOR_ANS_AUTHPASSWORD [preauth]
debug3: mm_request_receive_expect entering: type 13 [preauth]
debug3: mm_request_receive entering [preauth]
debug3: mm_request_receive entering
debug3: monitor_read: checking request 4
debug3: mm_answer_authserv: service=ssh-connection, style=, role=
debug2: monitor_read: 4 used once, disabling now
debug3: mm_request_receive entering
debug3: monitor_read: checking request 12
debug3: PAM: sshpam_passwd_conv called with 1 messages
debug1: PAM: password authentication failed for user: Authentication failure
debug3: mm_answer_authpassword: sending result 0
debug3: mm_request_send entering: type 13
Failed none for user from 127.0.0.1 port 36202 ssh2
debug3: mm_auth_password: user not authenticated [preauth]
debug3: userauth_finish: failure partial=0 next methods="publickey,password" [preauth]
debug3: send packet: type 51 [preauth]
/var/log/auth.log output:
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: recv_rexec_state: entering fd = 5
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: ssh_msg_recv entering
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: recv_rexec_state: done
Mar 23 11:09:52 manuel-nas sshd[23081]: debug2: parse_server_config: config rexec len 563
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: rexec:56 setting PasswordAuthentication no
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: rexec:61 setting ChallengeResponseAuthentication no
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: rexec:84 setting UsePAM yes
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: rexec:89 setting X11Forwarding yes
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: rexec:93 setting PrintMotd no
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: rexec:100 setting ClientAliveInterval 0
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: rexec:101 setting ClientAliveCountMax 3
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: rexec:113 setting AcceptEnv LANG LC_*
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: rexec:116 setting Subsystem sftp\t/usr/lib/openssh/sftp-server
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: checking syntax for 'Match Address 127.0.0.0/8'
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: checking syntax for 'Match user diskuser'
Mar 23 11:09:52 manuel-nas sshd[23081]: debug3: checking syntax for 'Match user diskuser-privat'
Mar 23 11:09:52 manuel-nas sshd[23081]: debug1: sshd version OpenSSH_7.4, OpenSSL 1.0.2l 25 May 2017
Mar 23 11:09:52 manuel-nas sshd[23081]: debug1: private host key #0: ssh-rsa SHA256:< removed for confidentiality >
Mar 23 11:09:52 manuel-nas sshd[23081]: debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:< removed for confidentiality >
Mar 23 11:09:52 manuel-nas sshd[23081]: debug1: private host key #2: ssh-ed25519 SHA256:< removed for confidentiality >
Mar 23 11:09:52 manuel-nas sshd[23081]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=127.0.0.1 user=user
ssh output: Note: In the logs I can see that my login attempt is already rejected when the password prompt appears
$ ssh 127.0.0.1 -p2222
[email protected]'s password:
|
In your PAM configuration (which is distribution specific) make sure that pam_unix.so line for sshd has the nullok argument, e.g.:
auth required pam_unix.so try_first_pass nullok
Otherwise pam_unix will prevent this, cf. the pam_unix man page:
The default action of this module is to not permit the user access to a service if their official password is blank. The nullok argument overrides this default.
| Keyless, passwordless SSH login on localhost not possible, PAM relation assumed |
1,542,878,501,000 |
In /etc/ssh/sshd_config I uncomment option PasswordAuthentication no and restart the service via service sshd reload. But password authentication is still available. Why?
|
The debug log (run ssh with -vvv arguments) would give you more clue about what is going on in the connection.
The password authentication is not the only one which can prompt you for some kind of password. There is always keyboard-interactive, which behaves very similarly and is usually used by PAM. It is controlled by the ChallengeResponseAuthentication option, which defaults to yes. If you want to disable it, you need to put this option with no into the configuration explicitly.
Also do not disable PAM (UsePAM). It is not used only for authentication, but also for setting up session of the user and other steps around authentication. It might work for you now, but it might break in future or for somebody else who will be using different system.
| ssh disable password authentication |
1,542,878,501,000 |
Using the default OpenSSH sshd package for Debian, is there any way to configure it to treat every username as being the same?
For instance, if someone connected with a random username (ie: 8LaRiQRd8Qjh), which did not exist as a Linux user, could I configure sshd to treat that as some consistent username like "testuser"?
I know how this could be done from the SSH client perspective, but I want the SSH server itself to accept any connection credentials (allowing my shell to handle authentication at that level).
Ideally what I want is a rule like "If there is no existing username, use this one instead". Even "always use this username" is okay, just less ideal.
It would be nice to find a simple solution using the default OpenSSH sshd service, rather than running my own sshd service.
|
I have no idea why you're trying to do this, and it seems like a terrible idea.
That said, for some reason the question got me hooked and I needed to find an answer.
The short answer is that this can't readily be done by simply configuring the available packages in debian.
If you want to do this you have to write two modules: one for NSS and one for PAM.
For the NSS module you will need to provide at least _getpwbynam_r. For the PAM module there's a lot more boilerplate.
This seems like a lot of work and not what you're looking for, but since you mention that you want to take care of authentication yourself, this is the way to do it.
A much simpler option (and probably a lot less secure) would be to use paramiko to setup a Python SSH server and customize/hook the authentication functions.
Fortunately, the guys at paramiko have already done most of the heavylifting in this demo server they have at their repo.
By replacing the check_auth_password or check_auth_publickey you can accept any user as valid. An example for password auth(*):
# pip install pam
import pam
MYUSER = 'testuser'
class Server(paramiko.ServerInterface):
def check_auth_password(self, username, password):
if password and pam.authenticate(username=MYUSER, password=password):
return paramiko.AUTH_SUCCESSFUL
return paramiko.AUTH_FAILED
Since this isn't StackOverflow I'm gonna stop there :)
This will create an ssh server that will ignore usernames for password authentication and will check the given password against testuser.
By default this server will prompt for a name and exit. You might want to replace that with a shell or your custom app.
I hardcoded the username, but you could just as easily get it from a config file or a database lookup or whatever.
You might also want to replace the host_key variable and perhaps the port number.
There's so many ways to shoot yourself in the foot with this. You should be very very very careful. This code is not production ready, review the whole thing. If you don't find anything wrong in it you didn't do a good review ;-).
*: this is simply replacing a function in the Server class in demo_server.py and adding some stuff at the top
| Configuring an OpenSSH shell for any/every connecting username |
1,542,878,501,000 |
Basic setup:
- Operating System: CentOS 7 (64 bit)
- Grub 2
- separate boot partition with ext4
- luks encryption (aes-xts-plain64:sha512) on two disc partitions which both need to be unlocked by password at boot time
- after being unlocked both partitions are mounted on / as raid1 btrfs filesystem
Right now I am looking for a clean strategy to get remote access during boot time to unlock both partitions.
On a Raspberry Pi 2 I am already using Dropbear to do this and most of the threads I found seem to favourite this option for bigger systems too. Even though on bigger systems nobody cares about the bootloader resources needed.
Question:
From my understanding on a CentOS 7 Grub2 (clean installation) I already have an OpenSSH service running by default. Why do I need to install dropbear then if openSSH and dropbear do the same job?
Shouldn't I be able to configure openSSH for grub and just paste the command:
/lib/cryptsetup/askpass "passphrase: " > /lib/cryptsetup/passfifo
diretly over openSSH?
|
So is dropbear really like the right and only choice for remote access during boot time?
I did some additional research on dracut which is used to build the initramfs image on CentOS and it shows the option "--sshkey " which needs to be combined with the module load option "ssh-client" in /etc/dracut.conf.
It looks to me again as if there already is a ssh-client at place and I do not need to install dropbear additionally. Has anyone tried this
option before? Does anyone know a good tutorial for this?
| How to use openSSH for disc encryption at boot time (OpenSSH vs. Dropbear) |
1,542,878,501,000 |
I found missing information in the manpage for scp when using IP6: there is no hint that you have to use slash masked brackets around the IP when using scp -6:
scp -6 user@\[2001:db8:0:1\]:/tmp/test.file /tmp
How can I submit a change to the scp manpage?
|
The information you seek is here:
COLOPHON
This page is part of the openssh (Portable OpenSSH) project. Informa‐
tion about the project can be found at
http://www.openssh.com/portable.html. If you have a bug report for
this manual page, see http://www.openssh.com/report.html. This page
was obtained from the tarball openssh-6.6p1.tar.gz fetched from‐
http://ftp.eu.openbsd.org/pub/OpenBSD/OpenSSH/portable/
on 2014-07-09. If you discover any rendering problems in this HTML
version of the page, or you believe there is a better or more up-to-
date source for the page, or you have corrections or improvements to
the information in this COLOPHON (which is not part of the original
manual page), send a mail to [email protected]
| Submit an updated manpage |
1,542,878,501,000 |
There are six key files in /etc/ssh directory for private and public keys. 4 of them are for DSA and RSA public & private keys. but there are two more files named ssh_host_key and ssh_host_key.pub, what are these keys?
|
ssh_host_key is the private key if you use the SSHv1 protocol and ssh_host_key.pub is the matching public key.
It should be a RSA key.
If you use SSHv2 you chose between multiple signing algorithms like DSA, RSA and ECDSA and then the ssh_host_ecdsa_key and etc are used.
| What are all of the SSH Key files? |
1,542,878,501,000 |
I have recently upgraded my workstation - Fedora 31 to Fedora 34. As it usually happens after upgrade some of ssh alogrithms become obsoleted and I have to add extra lines to .ssh/config and I am okay with that doing my best on security.
This time ssh-rsa term confuse me a lot. I have old RSA public key, for instance it worked to authorize my openssh client against Debian 10, Debian 8 and Cisco 4k router.
After upgrade I have to add PubkeyAcceptedKeyTypes +ssh-rsa to .ssh/config for most of older hosts, in this case it would be Debian 8 and Cisco 4k router. Now I can log in like i used to. But Cisco 4k log a message:
Public-key Algorithm compliance violation detected.Kindly note that weaker Public-key Algorithm 'ssh-rsa' will be disabled
Here are my questions:
If Cisco 4k allow higher PK than ssh-rsa, why it does not work with default ssh settings?
Is there any connection between key type "ssh-rsa" and allowed PK algorigthms, e.g. does public key type limit allowed algorightms by key length or anything?
This authentication is always referred as ssh-rsa, but if I have to add it manually to config - what real PK authentication is used by default? Is it a sort of ssh-rsa or even some other type?
Is there any way (I have tried ssh debug and sshd debug) to understand clearly what PK algorithms are supported on server and client like we do with ciphers?
Update:
New information about Cisco 4k router:
By default Cisco support host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa
I have added PubkeyAcceptedKeyTypes +rsa-sha2-512 and I can log in, but still get warning about ssh-rsa.
Considering rsa-sha2-512 as a sort of ssh-rsa (because they both were dumped in recent openssh) my additional questions are:
Does router statement seems to refer ssh-rsa as any type of ssh-rsa including rsa-sha2-512?
Does host key algorithms enabled in router seem to be limited by some other means?
|
For background...
There's a great answer on the topic over on Security Stack Exchange which links through to openssh's notes on deprecating ssh-rsa.
It seems the problem is that the original ssh-rsa algorithm (described in RFC 4253) relied on SHA-1 which is now largely defunct for cryptography:
Since 2005, SHA-1 has not been considered secure against well-funded opponents; as of 2010 many organizations have recommended its replacement. NIST formally deprecated use of SHA-1 in 2011 and disallowed its use for digital signatures in 2013. As of 2020, chosen-prefix attacks against SHA-1 are practical.
But it's the signature algorithm that used SHA-1 not the key itself.
With that in mind...
If Cisco 4k allow higher PK than ssh-rsa, why it does not work with default ssh settings?
What's changed is that openssh no-longer allows ssh-rsa by default. The change you made lets your client accept ssh-rsa. So the router still accepts it (even if it moans). But there's no strict hierarchy to the algorithms, just some "better" than others. So allowing "higher" algorithms doesn't mean that router and client share the same "higher" algorithms.
Another possible reason is that while your client and router both shared "better" algorithms, they weren't compatible with a raw RSA key. Eg: they allowed ssh certificates, but you have a key and no certificate. In that case you could use default settings but not your existing key with default settings.
Is there any connection between key type "ssh-rsa" and allowed PK algorithms
From what I can find on the topic, yes. They algorithms can be limited to a single cipher but don't typically care so much about key length. Keys are basically just [some] very large numbers. It doesn't matter how large they are, but the algorithm needs to know what to do with them.
Is there any way (I have tried ssh debug and sshd debug) to understand clearly what PK algorithms are supported on server and client like we do with ciphers?
Although it's a bit cryptic this is available with openssh level 2 debug (-vv). You'll see debug2: KEX algorithms: ... and debug2: host key algorithms: .... You should also see which algorithm was selected. There is also a level three debug (-vvv) if you want to delve deeper.
| SSH-RSA public key authentication explanation needed |
1,542,878,501,000 |
SSH by private IP is fine
I'm able to connect to a server through SSH by its private IP address:
C:\Users\m3>ssh -vvvvA [email protected]
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug3: Failed to open file:C:/Users/m3/.ssh/config error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolve_canonicalize: hostname 192.168.1.11 is address
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.168.1.11 [192.168.1.11] port 22.
debug1: Connection established.
debug3: Failed to open file:C:/Users/m3/.ssh/id_rsa error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_rsa.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_rsa type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_rsa-cert error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_rsa-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_rsa-cert type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_dsa error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_dsa.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_dsa type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_dsa-cert error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_dsa-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_dsa-cert type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_ecdsa error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_ecdsa.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_ecdsa type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_ecdsa-cert error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_ecdsa-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_ecdsa-cert type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_ed25519 error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_ed25519.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_ed25519 type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_ed25519-cert error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_ed25519-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_ed25519-cert type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_xmss error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_xmss.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_xmss type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_xmss-cert error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_xmss-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.10
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.10 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 192.168.1.11:22 as 'uconn'
debug3: hostkeys_foreach: reading file "C:\\Users\\m3/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file C:\\Users\\m3/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 192.168.1.11
debug3: Failed to open file:C:/Users/m3/.ssh/known_hosts2 error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
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: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none
debug2: compression stoc: none
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-nistp521,diffie-hellman-group-exchange-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],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-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:eyPiBvKLgJOk1xJc0k6cx9UnwIXbUUaXu9pPHTKt5Rg
debug3: hostkeys_foreach: reading file "C:\\Users\\m3/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file C:\\Users\\m3/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 192.168.1.11
debug3: Failed to open file:C:/Users/m3/.ssh/known_hosts2 error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
debug1: Host '192.168.1.11' is known and matches the ECDSA host key.
debug1: Found key in C:\\Users\\m3/.ssh/known_hosts:1
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
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug3: unable to connect to pipe \\\\.\\pipe\\openssh-ssh-agent, error: 2
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug2: key: C:\\Users\\m3/.ssh/id_rsa (0000000000000000)
debug2: key: C:\\Users\\m3/.ssh/id_dsa (0000000000000000)
debug2: key: C:\\Users\\m3/.ssh/id_ecdsa (0000000000000000)
debug2: key: C:\\Users\\m3/.ssh/id_ed25519 (0000000000000000)
debug2: key: C:\\Users\\m3/.ssh/id_xmss (0000000000000000)
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 51
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
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: Trying private key: C:\\Users\\m3/.ssh/id_rsa
debug3: no such identity: C:\\Users\\m3/.ssh/id_rsa: No such file or directory
debug1: Trying private key: C:\\Users\\m3/.ssh/id_dsa
debug3: no such identity: C:\\Users\\m3/.ssh/id_dsa: No such file or directory
debug1: Trying private key: C:\\Users\\m3/.ssh/id_ecdsa
debug3: no such identity: C:\\Users\\m3/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: C:\\Users\\m3/.ssh/id_ed25519
debug3: no such identity: C:\\Users\\m3/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: C:\\Users\\m3/.ssh/id_xmss
debug3: no such identity: C:\\Users\\m3/.ssh/id_xmss: 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
debug3: failed to open file:C:/dev/tty error:3
debug1: read_passphrase: can't open /dev/tty: No such file or directory
[email protected]'s password:
debug3: send packet: type 50
debug2: we sent a password packet, wait for reply
debug3: receive packet: type 52
debug1: Authentication succeeded (password).
Authenticated to 192.168.1.11 ([192.168.1.11]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting [email protected]
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug1: console supports the ansi parsing
debug3: Successfully set console output code page from:437 to 65001
debug3: Successfully set console input code page from:437 to 65001
debug3: receive packet: type 80
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug3: receive packet: type 91
debug2: channel_input_open_confirmation: channel 0: callback start
debug3: unable to connect to pipe \\\\.\\pipe\\openssh-ssh-agent, error: 2
debug1: ssh_get_authentication_socket: No such file or directory
debug2: fd 3 setting TCP_NODELAY
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug3: send packet: type 98
debug2: channel 0: request shell confirm 1
debug3: send packet: type 98
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-206-generic i686)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
0 packages can be updated.
0 of these updates are security updates.
New release '18.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Tue Mar 23 14:22:05 2021 from 192.168.1.52
SSH by public IP is bad
However, when using its public IP address, I run into an error:
ssh_exchange_identification: Connection closed by remote host
C:\Users\m3>ssh -vvvvA [email protected]
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug3: Failed to open file:C:/Users/m3/.ssh/config error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolve_canonicalize: hostname 11.111.11.111 is address
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 11.111.11.111 [11.111.11.111] port 22.
debug1: Connection established.
debug3: Failed to open file:C:/Users/m3/.ssh/id_rsa error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_rsa.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_rsa type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_rsa-cert error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_rsa-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_rsa-cert type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_dsa error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_dsa.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_dsa type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_dsa-cert error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_dsa-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_dsa-cert type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_ecdsa error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_ecdsa.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_ecdsa type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_ecdsa-cert error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_ecdsa-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_ecdsa-cert type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_ed25519 error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_ed25519.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_ed25519 type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_ed25519-cert error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_ed25519-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_ed25519-cert type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_xmss error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_xmss.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_xmss type -1
debug3: Failed to open file:C:/Users/m3/.ssh/id_xmss-cert error:2
debug3: Failed to open file:C:/Users/m3/.ssh/id_xmss-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\m3/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7
ssh_exchange_identification: Connection closed by remote host
How to debug
What could be the cause? How can I debug the issue?
Router port forwarding
The server has the private IP address. But there is a router, with public IP address, which forwards the SSH 22 port to the private IP address.
sshd log
Suggested here, I used this command on server to log sshd output:
$ tail -f -n 500 /var/log/auth.log | grep 'sshd'
When I run ssh [email protected] on client I get the following log:
Mar 23 17:26:10 server-homeshine sshd[1355]: Accepted password for uconn from 192.168.1.52 port 53107 ssh2
Mar 23 17:26:10 server-homeshine sshd[1355]: pam_unix(sshd:session): session opened for user uconn by (uid=0)
But when I run ssh [email protected] on client, no log is displayed whatsoever. I think it is implied that the router is not forwarding the 22 port when a public IP address is used. Not sure why.
SSHD config
Server sshd config is:
uconn@server-homeshine:/etc/ssh$ cat sshd_config
# Package generated configuration file
# See the sshd_config(5) manpage for details
# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
ListenAddress ::
ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024
# Logging
SyslogFacility AUTH
LogLevel INFO
# Authentication:
LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes
# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes
# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no
#MaxStartups 10:30:60
#Banner /etc/issue.net
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
IP tables
Here is the IP tables on server:
$ sudo iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
$ sudo ip6tables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
Routing table
Server routing table:
$ sudo route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 enp9s0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 enp9s0
Wireshark/Tshark
Installing tshark on server and examining the network packets, shows that when running ssh [email protected] (private IP) on a client, the SSH packets are received by server.
But when running ssh [email protected] (public IP) on a client, no SSH packet is received by server whatsoever.
The conclusion is that the ADSL router is not forwarding SSH packets to the server.
ZyXEL inquiry
Contacted ZyXEL on this issue and received this reply:
When doing port forwarding you need to make sure that the internal server has a gateway address pointing back to the gateway to be able to respond to outside request.
Also check that port 22 is not used by the gateway itself.
Server default gateway
My server default gateway is 192.168.1.1 which is what it should be:
$ ip r
default via 192.168.1.1 dev enp9s0 onlink
192.168.1.0/24 dev enp9s0 proto kernel scope link src 192.168.1.11
|
Port 22 incoming is closed by ISP for security reasons. Figured it out by contacting the ISP.
Changed the SSHD port from 22 to 2222:
$ sudo vim /etc/ssh/sshd_config
$ sudo systemctl restart sshd
Now I'm able to SSH to public IP address by using the custom port:
>ssh [email protected] -p 2222
| How to debug: ssh_exchange_identification: Connection closed by remote host |
1,549,314,696,000 |
I've discovered that OpenSSH is capable of forwarding UNIX sockets like this:
ssh -R /var/run/program.sock:/var/run/program.sock
My question is whether this extends to abstract unix sockets too.
I've tried the following to no avail:
ssh -nNT -R @laminar:@laminar
ssh -nNT -R unix-abstract:laminar:unix-abstract:laminar
The program in question does support file-based unix sockets, but as it uses abstract sockets by default I'd like to avoid reconfiguring it to simplify matters if possible.
OpenSSH (client) version: OpenSSH_7.4p1 Raspbian-10+deb9u4, OpenSSL 1.0.2q 20 Nov 2018
OpenSSH (server) version: OpenSSH_7.6p1 Ubuntu-4ubuntu0.1, OpenSSL 1.0.2n 7 Dec 2017
|
No, that's not possible with the standard openssh-portable.
You can look for instance at the unix_listener() function here.
Maybe there are patches floating around, but I'm not going to answer with google search results ;-)
Adding such a thing should be technically easy, but who's going to deal with the "political" part, ie. convince the openssh developers to include the patch?
FWIW, such a patch should necessarily check the peer credentials of the clients connecting to the socket by default; openssh already includes the necessary compat code for that.
| Forward abstract unix socket over SSH? |
1,549,314,696,000 |
I've freshly setup a rather standard current Arch Linux and encounter a problem that I can not get a grip on:
DHCP service is enabled and network is online (ping succeeds with hostname and IP address)
OpenSSH service is enabled
OpenSSH config allows public key and password
But I can not connect via SSH unless I also log in locally. Once I logged in locally once, I can logout in and out via SSH without problems, even when the local session is exited.
Journal says that SSH server starts up well before the local login.
Edit: Error message from Putty is "Connection refused"
|
You need to install and enable haveged to generate sufficient entropy for the cryptographic exchange of keys. Possibly related to this bug report.
| SSH only after login? |
1,549,314,696,000 |
I need a second openssh server source modified and running on debian.
The modifications I made on the source code are not really relevant, anyway they amplify the logs.
I compiled the modified openssh-7.4p1 with
./configure --prefix=/opt --enable-pam --with-pam
make ; make install
Then I created /lib/systemd/system/ssh-mod.service :
[Unit]
Description=OpenBSD Secure Shell server modified to log
After=network.target auditd.service sshd.service
#ConditionPathExists=!/opt/etc/sshd-mod_not_to_be_run
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
[Service]
EnvironmentFile=-/opt/etc/default/ssh
ExecStart=/opt/sbin/sshd -D -f /opt/etc/sshd_config $SSHD_OPTS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify
[Install]
WantedBy=multi-user.target
Alias=sshd-mod.service
And /opt/etc/sshd_config is a standard ssh configuration file with the following lines:
Port 22
LogLevel INFO
ChallengeResponseAuthentication no
UsePAM yes
PrintMotd no
PidFile /var/run/sshd-mod.pid
Now I launched the service with:
$ sudo systemctl start ssh-mod
the command loops indefinetly, so I wait until the error message:
Job for ssh-mod.service failed because a timeout was exceeded.
See "systemctl status ssh-mod.service" and "journalctl -xe" for details.
then I check the status:
$ sudo systemctl status ssh-mod
● ssh-mod.service - OpenBSD Secure Shell server modified to log
Loaded: loaded (/lib/systemd/system/ssh-mod.service; enabled; vendor preset: enabled)
Active: activating (start) since Mon 2017-09-04 10:19:50 UTC; 12s ago
Main PID: 15701 (sshd)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/ssh-mod.service
└─15701 /opt/sbin/sshd -D -f /opt/etc/sshd_config
Sep 04 10:19:50 mymachine systemd[1]: ssh-mod.service: Service hold-off time over, scheduling restart
Sep 04 10:19:50 mymachine systemd[1]: Stopped OpenBSD Secure Shell server modified to log.
Sep 04 10:19:50 mymachine systemd[1]: Starting OpenBSD Secure Shell server modified to log...
Sep 04 10:19:50 mymachine sshd[15701]: Server listening on 0.0.0.0 port 22.
Sep 04 10:19:50 mymachine sshd[15701]: Server listening on :: port 22.
$ journalctl -xe
Sep 04 10:19:50 mymachine systemd[1]: ssh-mod.service: Start operation timed out. Terminating.
Sep 04 10:19:50 mymachine sshd[15549]: Received signal 15; terminating.
Sep 04 10:19:50 mymachine systemd[1]: Failed to start OpenBSD Secure Shell server modified to log.
-- Subject: Unit ssh-mod.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit ssh-mod.service has failed.
--
-- The result is failed.
Sep 04 10:19:50 mymachine systemd[1]: ssh-mod.service: Unit entered failed state.
Sep 04 10:19:50 mymachine systemd[1]: ssh-mod.service: Failed with result 'timeout'.
Sep 04 10:19:50 mymachine systemd[1]: ssh-mod.service: Service hold-off time over, scheduling restart
Sep 04 10:19:50 mymachine systemd[1]: Stopped OpenBSD Secure Shell server modified to log.
-- Subject: Unit ssh-mod.service has finished shutting down
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit ssh-mod.service has finished shutting down.
Sep 04 10:19:50 mymachine systemd[1]: Starting OpenBSD Secure Shell server modified to log...
-- Subject: Unit ssh-mod.service has begun start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit ssh-mod.service has begun starting up.
Sep 04 10:19:50 mymachine sshd[15701]: Server listening on 0.0.0.0 port 22.
Sep 04 10:19:50 mymachine sshd[15701]: Server listening on :: port 22.
Actually the service results as 'activating' but I can login on port 22 (the other server is listening to another port), so the shell seems working.
I have no clue what is causing this, the logs are not so explicit.
What am I missing? Why is the service hung?
Please tell me if you need more informations.
I followed the steps on the RedHat documentation.
|
I'm seeing the same behavior on another systemd system (Ubuntu 16.04.3 LTS, but provided by an HPC vendor that may have made modifications.)
From what I can tell, the problem is that Type=notify, and sshd isn't or can't send notification messages using sd_notify(3) or similar to systemd. So systemd never gets the message that it's started.
What I have done for now is to create an override in /etc/systemd/system/ssh.service (as a copy of /lib/systemd/system/ssh.service) and change Type from notify to forking. Then remove the -D from ExecStart, so sshd will fork its daemon.
Then systemctl daemon-reload, and restart ssh to make sure it's working.
The proper fix is to get the ssh service to work with Type=notify again, but I'm out of time for this today. Hope this is helpful to someone.
| OpenSSH Server start failed with result 'timeout' |
1,549,314,696,000 |
I have a file called hosts which looks as follow:
host1
host2
host3
host4
.....
On these machines there is also a local user named as the machine name. host1 user is created on host1 host and so on.
Is there a way to lock all these user accounts on all machines?
What I've used seems not to work properly.
pssh -h hosts -l root -i passwd -l hostname |cut -d. -f1
With this command I am hoping to lock each user account corresponding on each hostname.
I hope you get the idea of what I mean.
Thanks!
|
Build the command on the remote host, using the HOSTNAME variable to determine the host.
pssh -h hosts -l root -i 'passwd -l "$(hostname)"'
This assumes that the name of the user account to lock is what the machine thinks of as its name. If you're using nicknames in your SSH configuration and you want to use the nickname in the command rather than the machine's actual host name, or if the host name differs from the DNS host name, you can use $PSSH_HOST instead of $(hostname), but only if the remote host's server configuration allows passing that variable name in the environment, which is not the case by default on many systems.
| pssh (Parallel-ssh) passing different parameter for every host |
1,549,314,696,000 |
I try to establish a remote ssh connection.
I tried to connect "Remote" with ssh -fN -R 10110:localhost:22 GatewayUser@GatewayHost
and "Gateway" with ssh -p10110 RemoteUser@localhost
I got the response on the Gateway Console Connection closed by ::1
running it with -v ssh -v -fN -R 10110:localhost:22 GatewayUser@GatewayHost
produces that response in the Remote-Console
debug1: client_input_global_request: rtype [email protected] want_reply 1
debug1: client_input_global_request: rtype [email protected] want_reply 1
debug1: client_input_channel_open: ctype forwarded-tcpip rchan 2 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen localhost port 10110, originator ::1 port 48481
debug1: connect_next: host localhost ([127.0.0.1]:22) in progress, fd=4
debug1: channel 0: new [::1]
debug1: confirm forwarded-tcpip
debug1: channel 0: connected to localhost port 22
debug1: channel 0: free: ::1, nchannels 1
debug1: client_input_global_request: rtype [email protected] want_reply 1
debug1: client_input_global_request: rtype [email protected] want_reply 1
PS: a SSH connection from Remote to Gateway is working
Many thanks in advance!
__
Here the console-output when connecting from the gateway machineemanuel@UbuntuServer:~$ ssh -vvv -p10110 pi@localhost
OpenSSH_6.7p1 Ubuntu-5ubuntu1.3, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [::1] port 10110.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/emanuel/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/emanuel/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/emanuel/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/emanuel/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/emanuel/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/emanuel/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/emanuel/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/emanuel/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Ubuntu-5ubuntu1.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-4+deb7u2
debug1: match: OpenSSH_6.0p1 Debian-4+deb7u2 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug3: put_host_port: [localhost]:10110
debug3: load_hostkeys: loading entries for host "[localhost]:10110" from file "/home/emanuel/.ssh/known_hosts"
debug3: load_hostkeys: loaded 0 keys
debug1: SSH2_MSG_KEXINIT sent
Connection closed by ::1
emanuel@UbuntuServer:~$
|
What you do is: Crate a ssh connection from the raspi to the gateway, and forward the *:10110 from the gateway to 127.0.0.1:22 on the raspi.
Then you connect to port 10110@localhost, which may in some configurations use the ip6-address (::1) which has no tunnel behind it. sshd then closes the connection.
Try
ssh -4 -p10110 pi@localhost
This should get you one step further.
If you have problems finding the correct key (ssh stops after a certain amount of checked keys) then disable pubkeyauth with
ssh -oPubkeyAuthentication=no -4 -p10110 pi@localhost
| Reverse SSH "Connection closed by ::1" |
1,549,314,696,000 |
Is there any way to list the tunnels that SSH clients connected to my OpenSSH server have set up?
I can use e.g. lsof -i to show connections that are being actively tunnelled, but I'd like to be able to list tunnels that the clients have set up but may not currently be in use.
(It's just struck me that this may be an entirely client-side thing, i.e. the server only knows the client is set up to tunnel a port when something tries to connect through the tunnel, in which case the answer will be "you can't" - but I'll take that as an answer if so.)
(Background: I'm running a MineCraft server on a machine that won't be able to do much else while it's running. If I can monitor when users have tunnels set up, I can run up the MC server on demand.)
|
Well yes it is client sided.
Plus there isn't any configuration in the traditional sense. You create a tunnel by specifying the correct parameters when connecting to a server.
Sure you can store it in .bashrc, .ssh/config, or some other place for re-usability, but in general it is purely on-demand.
| List ports tunnelled on OpenSSH server |
1,549,314,696,000 |
The one thing that's been bothering me is, there is always concept of "ssh-ing" from client to server.
Might be a trivial question, but I just want to clear my mind. Which one do I choose to install on my host machine, openssh-server or openssh-client? How do I know if I want to install openssh-server or openssh-client on my or any other local or remote machine?
Let's say I want to ssh from client1 to client2. Do I have to install openssh-client or openssh-server on client2 and vice versa?
|
openssh-client contains the ssh client program /usr/bin/ssh, you use this to connect TO other machines running sshd or some other compatible ssh daemon. This package also contains other client-side programs like scp, sftp, ssh-keygen, ssh-agent, ssh-copy-id, and more.
openssh-server contains the ssh daemon /usr/sbin/sshd and the necessary startup scripts so that it gets started at boot time. This is used to listen for and handle incoming ssh connections FROM other machines.
You can have either or both (or neither) installed on a machine, depending on what role(s) (client and/or server) you want that machine to play.
In short:
to accept incoming ssh connections, install openssh-server
to make outbound ssh connections, install openssh-client
to do both, install both
| SSH client/server confusion |
1,549,314,696,000 |
Usually in the past I've always manually copied over my SSH public key to the remotes where necessary. I'm on a Mac and I finally decided to start using ssh-copy-id to make my life simpler, so I just used homebrew to install it.
I just used ssh-copy-id for the first time and am little confused by the result.
On my local machine, when viewing my id_rsa.pub key, it ends with username@machinename. I love this and it's made it easy to identify keys I can delete on remote machines later on.
I just used ssh-copy-id on my local machine to move my public key to a remote and then took a look at the authorized_keys file on the remote. I noticed that on the remote instead of my public key ending with myusername@mymachinename (as expected) it now ends with /Users/myusername/.ssh/id_rsa ??
Why the discrepancy? Is there any way to force ssh-copy-id to use username@machinename like it does on my local machine?
This might just be a misunderstanding I have with SSH and keys in general, but any thoughts are appreciated?
EDIT:
Just discovered that this only happens when I exclude my identity file and assume defaults.
Basically if I only do: ssh-copy-id user@hostname then I get this awkward comment in the authorized_keys file on the remote.
If I specify my public key: ssh-copy-id -i ~/.ssh/id_rsa.pub user@hostname then everything copies over as expected, using myusername@machinename as expected ?!
What's causing this oddity? The following link says that it should always default to using my id_rsa.pub file anyway, so I shouldn't need to specify it to get the right comment on the remote should I? http://linux.die.net/man/1/ssh-copy-id
|
Add option -i when running ssh-copy-id. This is explained in the manual:
Default behaviour without -i, is to check if 'ssh-add -L' provides any
output, and if so those keys are used. Note that this results in the
comment on the key being the filename that was given to ssh-add(1) when
the key was loaded into your ssh-agent(1) rather than the comment con-
tained in that file, which is a bit of a shame. Otherwise, if ssh-add(1)
provides no keys contents of the default_ID_file will be used.
| ssh-copy-id: why is the end of my public key different on my local vs remote? |
1,549,314,696,000 |
I can't seem to debug this issue, but I'm trying to set an rsa public key login method to one of my servers running CENTOS7. I used the "ssh-keygen -t rsa" command to generate keys and copied contents into ~/.ssh/authorized_keys. Here is the output to "ssh -i id_rsa user@ip_address". The method I used worked perfectly fine with my Debian server but not my CENTOS7 one.
Output:
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to <ip_address> [<ip_address>] port <port #>.
debug1: Connection established.
debug1: identity file id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to <ip_address>:<port #> as '<user>'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: [email protected] MAC:<implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC:<implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:<Finger print here>
debug1: Host '<ip_address>' is known and matches the RSA host key.
debug1: Found key in /<some location in my server>/known_hosts:2
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: id_rsa
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
sshd_config file:
# $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
PermitEmptyPasswords no
PasswordAuthentication no
# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes
# GSSAPI options
GSSAPIAuthentication no
GSSAPICleanupCredentials no
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
# problems.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Accept locale-related environment variables
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
# override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
|
StrictModes is on by default on CentOS, and other distributions.
If you created the files on the host that doesn't work that is the most likely cause of this issue.
Make sure that the ~/ssh/ on the remote machine is 700 and that the ~/.ssh/authorized_keys is set to 600.
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
If that doesn't fix the issue check your logs to see if SELinux is having issues or just relabel the directory with:
$ restorecon -Rv ~/.ssh
But if that is the issue you should have log entries in /var/log/audit on the remote machine.
| SSH publickey login permission denied on CENTOS But not on Debian |
1,549,314,696,000 |
I recently installed openSUSE, and I want to set up an ssh server so that I can ssh into this machine. However, I am having trouble installing openssh-server.
I have tried
$ sudo zypper install openssh-server
This is what this site says to type, but I get this message:
Package 'openssh-server' not found.
On my Ubuntu machine, if I type
$ sudo apt-get install openssh-server
or on my Fedora machine
$ sudo yum install openssh-server
everything works fine.
How can I install openssh-server on openSUSE? Do I have to manually add an RPM repository for it or something?
The solution doesn't need to use zypper, but I'd prefer not having to manually download and compile the source code.
|
There are two issues here:
openSUSE comes with openSSH pre-installed, so the ssh server does not need to be installed
https://nl.opensuse.org/OpenSSH
The packages for openSSH apparently have different names in openSUSE than they do in Ubuntu and Fedora (and maybe others?).
In Ubuntu (using apt-get) and Fedora (using yum), "openssh-server" is a valid package name
In openSUSE, the package "openSSH" covers both the SSH client and the SSH server
So if you type
sudo zypper install openssh
everything should work fine. Though, as I said previously, it should already be installed. It will tell you if it's already installed.
| How to install openssh-server on openSUSE? |
1,549,314,696,000 |
I want to create an account for my friend on my computer, but I don't want my friend to be able to view all my files. I saw that with OpenSSH, there is an option for that.
Inside the SSHD configuration file:
/etc/ssh/sshd_config
With the line:
ChrootDirectory /home/%u
However, the user home directory needs to be owned by root. Is that a bad thing? Are there any consequences or repercussions if admin owns the directory?
I tagged this question for 2 distributions and FreeBSD, since I use them all. I'm wondering if maybe the requirement of root owning the user home directory will be different between distributions and/or OS.
|
To answer your specific question, root must own the user home directory for the chroot provided by SSHD to work correctly. If the home directory is not owned by root, the user will be able to exit the directory when they connect via sftp.
There is no downside to root owning the user directory if the user is only connecting with sftp. However, if the user is also connecting another way (such as ssh) and being granted a shell, then you should use another solution, like the restricted shell rssh.
| OpenSSH, chroot user: Root needs to own the user directory, is there any consequence? |
1,549,314,696,000 |
I am trying to understand an sshd configuration that I believe should not work but does. The premise comes from a production system I’m working on; however, I simplified it for my own testing. Since I am unable to explain why this simple example works, I am also unable to explain why the more complex iteration works.
I have two servers, both with users Auser, Buser, and Cuser.
My client machine has an IP address of 192.168.10.1
My server has an sshd configuration that looks like this:
AllowGroups Cuser
Match Address 192.168.10.1
AllowGroups Cuser Buser
Match Address 192.168.10.1
AllowGroups Cuser Auser
According to the man pages for sshd_config(5)
Match Introduces a conditional block. If all of the criteria on the
Match line are satisfied, the keywords on the following lines
override those set in the global section of the config file, un-
til either another Match line or the end of the file. If a key-
word appears in multiple Match blocks that are satisfied, only
the first instance of the keyword is applied.
My interpretation is that from the client (192.168.10.1), only Cuser and Buser should be allowed to ssh to the server.
However when I test this, all three users: Auser, Buser, and Cuser have access. If I look in the sshd logs for the server, I see where each match block is applied:
Jul 25 10:48:59 server1 sshd[3525]: debug3: Trying to reverse map address 192.168.10.1.
Jul 25 10:48:59 server1 sshd[3525]: debug2: parse_server_config: config reprocess config len 854
Jul 25 10:48:59 server1 sshd[3525]: debug3: checking match for 'Address 192.168.10.1' user buser host client addr 192.168.10.1 laddr 192.168.10.4 lport 22
Jul 25 10:48:59 server1 sshd[3525]: debug1: connection from 192.168.10.1 matched 'Address 192.168.10.1' at line 138
Jul 25 10:48:59 server1 sshd[3525]: debug3: match found
Jul 25 10:48:59 server1 sshd[3525]: debug3: reprocess config:139 setting AllowGroups cuser buser
Jul 25 10:48:59 server1 sshd[3525]: debug3: checking match for 'Address 192.168.10.1' user buser host fedora addr 192.168.10.1 laddr 192.168.10.4 lport 22
Jul 25 10:48:59 server1 sshd[3525]: debug1: connection from 192.168.10.1 matched 'Address 192.168.10.1' at line 140
Jul 25 10:48:59 server1 sshd[3525]: debug3: match found
Jul 25 10:48:59 server1 sshd[3525]: debug3: reprocess config:141 setting AllowGroups cuser auser
So, interestingly, from my interpretation of the man pages, I would have expected only the first “reprocess config:139” line to be applied as it is the first instance of the AllowGroups keyword. However, looking at the logs, since I see “reprocess config:141 setting AllowGroups cuser auser”, I might only expect the second instance to be applied.
However, neither of these interpretations seem correct since all three users are able to connect.
So, with some additional testing I changed my sshd_config to look like this:
AllowGroups Cuser
Match Address 192.168.10.1
AllowGroups Cuser Buser
Match Address 192.168.10.1
AllowGroups Auser
and
AllowGroups Cuser
Match Address 192.168.10.1
AllowGroups Auser
Match Address 192.168.10.1
AllowGroups Cuser Buser
All three users were still able to login.
And one final test
AllowGroups Cuser
Match Address 192.168.10.1
AllowGroups Buser
Match Address 192.168.10.1
AllowGroups Auser
Finally, only Auser and Buser have access.
It's almost as if the first Match block will override any default settings, but subsequent match blocks append to any previous match blocks.
|
I wasn't able to trace through the code as closely as I hoped, but I think I have a sense of what's happening. A very significant clue is in the source code file for the routines that parse the command-line arguments, the sshd_config file, and its included files:
/*
* The strategy for the Match blocks is that the config file is parsed twice.
*
* The first time is at startup. activep is initialized to 1 and the
* directives in the global context are processed and acted on. Hitting a
* Match directive unsets activep and the directives inside the block are
* checked for syntax only.
*
* The second time is after a connection has been established but before
* authentication. activep is initialized to 2 and global config directives
* are ignored since they have already been processed. If the criteria in a
* Match block is met, activep is set and the subsequent directives
* processed and actioned until EOF or another Match block unsets it. Any
* options set are copied into the main server config.
*/
There is essentially one routine that reads the config keywords and arguments (like Compression no and AllowGroups foo bar baz) through the three phases of parsing: command-line arguments, the first pass that skips the Match blocks, and the second pass that reads the Match blocks. There are a couple of flag variables that track which phase the parsing is in - one for the command-line parsing and another for the first and second file passes.
AllowGroups, DenyGroups, AllowUsers, and DenyUsers are parameters that take multiple values rather than a single value. So the routine parses out the list of arguments on the line and appends each argument to an array of strings. While there's a flag for the first and second file passes, there's no flag for "this is a new Match block".
This means when the first Match block is parsed (the start of the second pass) and it contains an AllowGroups parameter, the existing list of values (before the Match blocks) will be wiped and replaced with the new arguments in the Match block. However, nothing signals the routine to wipe the list again when a second Match block also matches and is parsed. If AllowGroups were a single-valued parameter, each new instance would be ignored in favor of the first one. However, since it's a multi-value parameter, the new arguments are instead appended to the list. This is the behavior that puzzled you when you uncovered it. (Me too)
My guess is the authors of the parsing routine didn't envision a config like your test server - having multiple valid Match blocks that set the same multi-value parameter. The more typical case is that only one of the Match blocks will succeed and be parsed because they match different things. Or if multiple blocks succeed, the reason for multiple blocks is because each one sets different parameters.
In my comment a couple of days ago I mentioned that these four parameters work in a way that's not intuitive. Even though it's not directly an answer to this question, I'll add my findings here (for posterity).
After a connection has come in and the second pass config parsing is finished, the code then checks the Allow/Deny groups to see which ones apply. They're checked in this order: DenyUsers, AllowUsers, DenyGroups, and AllowGroups. The test and decision to allow/deny works like this pseudo-code:
if DenyUsers has > 0 items and user is one of them
deny
if AllowUsers has > 0 items and user is not one of them
deny
if DenyGroups has > 0 items and user is member of one of them
deny
if AllowGroups has > 0 items and user is not a member of any of them
deny
allow
As soon as a 'deny' decision is reached, the routine stops checking further. So the 'AllowUsers' list doesn't work in the intuitive way. If you put any names in the 'AllowUsers' list, all the other users (not in the list) are denied. It doesn't matter if the other users are in the 'AllowGroups' list, because the code stops checking before it consults 'AllowGroups'. And any groups in the 'AllowGroups' list will cause users who don't belong to those groups to be denied, even if they are listed in 'AllowUsers'.
| sshd_config with Multiple Match Address |
1,549,314,696,000 |
I'm writing some integration tests, that test SSH connections between servers.
For the time being the tests are run from people's laptops. In order not to muck around in the user's (the user running the tests) ~/.ssh/config I create a temporary directory with a bespoke ./tmp/.ssh/config file just for the tests. Then I export HOME=/path/to/tmp. Unfortunately, I've found that openssh doesn't use $HOME to search for an ssh config or identity files.
This is ok if I'm ssh-ing directly to a host, because I can just explicitly set my config using the -F flag. However, if I'm ssh-ing through a bastion and I have a proxycommand, ssh does not pass that configuration file down to my proxycommand. So, if my bespoke ssh config uses a different default username (for example), that configuration won't be used for the proxycommand.
I "could" modify the proxycommand as well (to take an ssh config file as an argument), however, I'd like to know if it's possible to get openssh to look for the config/identity files in a different location just by use of environment variables (without having to pass the configuration file down to each subsequent downstream command). I can change my ssh-agent using SSH_AUTH_SOCK so I was hoping to be able to change the config file directory as well.
|
According to the source code, ssh gets the home directory from the password file and then, if it does not succeed, from the HOME environment variable.
What you can do is add an Include to every user's ~/.ssh/config, say ~/tmp/user/.ssh/config.
If the file to be included does not exist, ssh will not complain. But if it exists and is readable, it will include it. That should allow you to do the tests without messing too much with their files.
Notice that it poses a security risk. Anybody knowing those paths will be able to inject local configurations for other users if you don't secure them well.
| OpenSSH not respecting $HOME when searching for ssh config files |
1,549,314,696,000 |
Here is my use case: I have a script that lists through hundreds of servers and tests whether or not they allow logins using public key authentication using a specific private key (in the ssh client's .ssh directory). Some of these servers were misconfigured, and I do not have control over the SSH service on any of these servers.
Here is what I have so far:
ssh -o ConnectTimeout=2 -o PasswordAuthentication=no -q $x exit
returncode=$?
So this works so far for most servers (i.e., returns a non-zero return code when a server is unreachable, and 0 when the server can be logged-in to), until some troublesome server fails due to some SSH misconfiguration (ex. ~/.ssh on the remote server has an incorrect permission. Here is a related thread describing what can be done in such case.
But i don't want to fix the remote servers. I just want SSH to fail and exit with a non-zero return code if SSH key authentication fails.
Any ideas how to get around this?
Thanks in advance.
|
As per suggestion,
ssh has a -o batchmode=yes option that will prevent any interaction.
no password asked
no confirmation for foreign signature
This will result in error code if no connection is make.
| scripted ssh should not ask for a password if public key authentication fails |
1,549,314,696,000 |
How to get the return code of SFTP command?
I do this to download all files from a directory. But if the directory is empty the command returns 1
How to fetch the actual code for File not found?
echo 'get * /var/download' | sftp -b - user@host
Or a solution would be to ignore/suppress the error File not found and return 0 (not suppress all errors, only this one)
|
OpenSSH sftp returns 0 on success and 1 on error.
No further distinction is provided.
To test, if any file exists in a directory before trying to download them, you can use:
echo "ls /remote/path/*" | sftp -b - [email protected]
if [ $? -eq 0 ]
then
echo "Files exist, can download now"
echo 'get /remote/path/* /local/path/' | sftp -b - [email protected]
if [ $? -eq 0 ]
then
echo "Files successfully downloaded"
else
echo "Files exist, but failed to download"
fi
else
echo "Files do not exist"
fi
For a similar question, see How to check if file exists in remote SFTP server from local Linux script?
| Test if any file was downloaded with SFTP command |
1,549,314,696,000 |
I'm using this .ssh/config:
Host myserver
HostName 12.34.67.89
User anyuser
IdentityFile /root/.ssh/anything_rsa
But running ssh myserver returns a Permission denied (publickey) error.
Why isn't the given identity file (root/.ssh/anything_rsa) be used? Instead it seems to use /root/.ssh/id_rsa
OpenSSH_7.0p1, OpenSSL 1.0.1r 28 Jan 2016
debug1: Connecting to myserver [12.34.67.89] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 pat OpenSSH* compat 0x04000000
debug1: Authenticating to myserver:22 as 'admin'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: XXXXX
debug1: Host 'myserver' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:4
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
Running ssh -v -i /root/.ssh/anything_rsa -l anyuser myserver is working. So it seems the config file is not used properly... I don't understand that at all...
|
The comments below your post indicate that /root/.ssh is a symlink to another directory. I have never had a reason to use a symlinked .ssh directory, but I'm fairly certain that ssh will entirely ignore an .ssh directory that is either not owned by the user in question, or is group- or world-readable. IOW, it must be chown root and chmod 0700 for ownership and permissions. My hunch is that the target directory (/etc/config/ssh) of your symlink either is not owned by root, or is not 0700, and so ssh is ignoring your config file and using the default IdentityFile name of id_rsa.
Update: your comments below this post indicate that, although you are referencing an IdentityFile in root's .ssh directory, you are not actually running as root. The section below has been edited to reflect your username of admin.
For purposes of troubleshooting, consider trying:
cd ~admin
mkdir .ssh
chmod 700 .ssh
cp -RLp /etc/config/ssh/* .ssh
chown -R admin .ssh
Then try again.
| SSH: Permission denied as given IdentityFile is not used |
1,549,314,696,000 |
For all my servers PasswordAuthentication is set to no in the sshd_config file. This means that only key authentication is allowed.
In this situation, is there any risk if PasswordAuthentication is set to yes in the client's ssh_config?
|
There's a risk, if the client connects to the wrong machine, and that machine allows password auth. Then the user may enter their password, thinking it might be a server side change... and now the password can be stolen.
Related: Is your SSH password revealed when you attempt to connect to the wrong server?
| OpenSSH: if the server is set to "PasswordAuthentication no" then is there any risk if the *client* is set to "PasswordAuthentication yes"? |
1,549,314,696,000 |
I usually have to access a couple of remote and local SSH hosts, this works perfectly, I actually want to have to type in the passphrase every time.
However, there's a single SSH host on my local network that I have to log into a lot more frequently than the rest. Security is not much of a problem with this one in particular, although connecting without keys is out of the question. Is there any kind of configuration which would allow me to not enter the passphrase for this single SSH host?
I hope I'm not asking something that doesn't even make sense...
Thank you.
Edit: I apologize for not clarifying, every server and my client are running Linux, there's no other OS involved in any way.
|
It sounds like you want to use two different sets of keypairs. Have one prompt you for your password every time, and set up the other one to be passwordless. Copy the passwordless set's public key to the server (or servers) you want to connect to more quickly.
| How to log into a single SSH host without passphrase? |
1,549,314,696,000 |
I have my desktop in the office. When X starts, ssh-agent starts automatically. I have to add my SSH key once, at the beginning, and then I can use ssh without having to enter my password each time.
However, when I connect to my desktop via SSH (i.e. from home) the ssh-agent is not accessible and I have to provide my key every time. Also, even if I start a new instance of ssh-agent, I still cannot connect to it.
Is there a way to use ssh-agent on a remote system (to which I am connected via ssh?
|
You can use agent forwarding: make sure to include ForwardAgent yes in your client-side configuration (~/.ssh/config), or use the -A command line option. (This feature can be disabled on the server side (AllowAgentForwarding in sshd_config), but this is only useful for restricted accounts that cannot run arbitrary shell commands.) This way, all the keys from your local machine are available in the remote session. Note that enabling agent forwarding on the client side has security implications: it gives the administrator of the remote machine access to your keys (for example, if you are at A and have a key for B and a key for C, and enable agent forwarding in your connection to B, then this lets B access your keys and hence log into C).
If you want to make the agent from your X session on the office machine available in the SSH sessions from home, then you need to set the SSH_AUTH_SOCK environment variable to point to the same file as in the X session. It's easy enough to do manually:
export SSH_AUTH_SOCK=/tmp/ssh-XXXXXXXXXXXX/agent.12345
where XXXXXXXXXXXX is a random string and 12345 is the PID of the agent process. You can automate this easily if there is a single running agent (find /tmp -maxdepth 1 -user $USER -name 'ssh-*') but detecting which agent you want if there are several is more complicated.
You can extract the value of SSH_AUTH_SOCK from a running process. For example, on Linux, if your window manager is Metacity (the default Gnome window manager):
env=$(grep -z '^SSH_AUTH_SOCK=' /proc/$(pidof -s metacity)/environ')
if [ -n "$env" ]; then export "$env"; fi
Alternatively, you can configure your office machine to use a single SSH agent. If the agent is started automatically when you log in, then in most distributions, it won't be started if there is already a variable called SSH_AUTH_SOCK in the environment. So add a definition of SSH_AUTH_SOCK to your ~/.profile or ~/.pam_environment, and manually start ssh-agent if it isn't already started in .profile:
export SSH_AUTH_SOCK=~/.ssh/$HOSTNAME.agent
if [ -z "$(pgrep -U "$USER" ssh-agent)" ]; then
ssh-agent >/dev/null
fi
| using ssh-agent |
1,549,314,696,000 |
I work on remote servers frequently, but for some reason I cannot discern, today I am unable to ssh into anything.
Everything comes back with Write failed: broken pipe.
I know this is a common symptom of server timeouts, but I can't do anything besides enter a password.
When connecting, the password dialog is normal, and does recognize invalid attempts. However, as soon as the correct password is entered, the broken pipe hits.
I did try apt-get install --reinstall openssh , but it didn't fix anything.
Any thoughts?
This is on ubuntu 11.04, but ditching Gnome for OpenBox.
--
ssh -v output:
~ >> ssh -v [email protected]
OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to turnleftllc.com [72.167.39.231] port 22.
debug1: Connection established.
debug1: identity file /home/tom/.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/tom/.ssh/id_rsa-cert type -1
debug1: identity file /home/tom/.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/tom/.ssh/id_dsa-cert type -1
debug1: identity file /home/tom/.ssh/id_ecdsa type -1
debug1: identity file /home/tom/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5
debug1: match: OpenSSH_5.5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.8p1 Debian-1ubuntu3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
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
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 87:81:14:42:23:b7:5b:94:eb:a9:f5:25:e0:e9:1a:0b
debug1: Host 'turnleftllc.com' is known and matches the RSA host key.
debug1: Found key in /home/tom/.ssh/known_hosts:9
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
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
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/tom/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to turnleftllc.com ([72.167.39.231]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Write failed: Broken pipe
Trying the above with a different server yielded almost identical results.
For good measure, here's -vvv using a different server.
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/tom/.ssh/id_rsa
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 DSA public key: /home/tom/.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: Trying private key: /home/tom/.ssh/id_ecdsa
debug3: no such identity: /home/tom/.ssh/id_ecdsa
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
[email protected]'s password:
debug3: packet_send2: adding 48 (len 63 padlen 17 extra_pad 64)
debug2: we sent a password packet, wait for reply
debug1: Authentication succeeded (password).
Authenticated to 50.57.55.206 ([50.57.55.206]:22).
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 LS_COLORS
debug3: Ignored env LIBGL_DRIVERS_PATH
debug3: Ignored env SSH_AUTH_SOCK
debug3: Ignored env USERNAME
debug3: Ignored env DEFAULTS_PATH
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
debug3: Ignored env GNOME_KEYRING_PID
debug1: Sending env LANG = en_US.UTF-8
debug2: channel 0: request env confirm 0
debug3: Ignored env GDM_LANG
debug3: Ignored env MANDATORY_PATH
debug3: Ignored env UBUNTU_MENUPROXY
debug3: Ignored env PS1
debug3: Ignored env GDMSESSION
debug3: Ignored env SHLVL
debug3: Ignored env HOME
debug3: Ignored env LANGUAGE
debug3: Ignored env LOGNAME
debug3: Ignored env XDG_DATA_DIRS
debug3: Ignored env DBUS_SESSION_BUS_ADDRESS
debug3: Ignored env LESSOPEN
debug3: Ignored env WINDOWPATH
debug3: Ignored env DISPLAY
debug3: Ignored env LESSCLOSE
debug3: Ignored env COLORTERM
debug3: Ignored env XAUTHORITY
debug3: Ignored env _
debug2: channel 0: request shell confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
Write failed: Broken pipe
|
When I have seen this kind of behavior, it's usually something network related.
You didn't mention if you were connecting from work or home. If you are connecting from home, I would reboot the personal router connecting to the internet. If you are connecting from work, I would check with the networking group and find out if something has changed. A new IPS/IDS? New definitions or thresholds for the IPS/IDS? New firewall policy? New timeout value?
I feel like you may want to start looking outside of SSH.
| Can't SSH into Any Server |
1,549,314,696,000 |
I am trying to completely disable SSH comments.
Running ssh-keygen -C "" -f test results in:
ssh-keygen -l -f test.pub
3072 SHA256:Ir9Q4ykMBl0zx/NaCQGGx/qmEFIX84qaHDzFA0SzevE no comment (RSA) # (1) no comment
ssh-keygen -l -f test
3072 SHA256:Ir9Q4ykMBl0zx/NaCQGGx/qmEFIX84qaHDzFA0SzevE test.pub (RSA) # (2) comment!
ssh-keygen -e -f test.pub
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "3072-bit RSA, converted by cppbest@home from OpenSSH" # (3) comment!
AAAAB3NzaC1yc2EAAAADAQABAAABgQC2PJOMG6g3qpX02Rki5hfqU6//fw78xhyK6tKLqm
piJyI3uD9P5W2nzblJ7dk+B85PTM6c6S95Qq47UBcMnALXCIQ6kRazoZDOaUk9f/BxbEIg
kCaJWX5CVEib52lyF2jH/FEs5kIUJW40II1RVYfWdMKqd08ZPPfAUt6MUj3Rac7d7PHQT5
Cns8zfgba0GIHqktZQYC1oqRfhSTZtvkeX9zTXfZq3DXJ7vJBnNB+r/GddnrU2BkRqlLDw
tVN8WOS8dJvULzMjTJxMwCdIpWXcmN2n3HVBASZom8OCEEaCAFN1QCd9JmqFDAZzio8ZK/
0Q/RvW1o5udhC77JnFye+u8brfT0IENhs5LefcxfKEEdwcD+8ofcEfmxGzIggkvNGYXH14
Z83Cmwla17QmwRSTpKQnv/DYaVncXvkltDkylfhWNzd3yTC73L52aSbzuVlxjqX8LYr6Ir
LwzrQ9ZyNzaWivlgxMPaYJlui1kewd1/n+hTW304SUQ/UOeMbUCRU=
---- END SSH2 PUBLIC KEY ----
Is it possible to disable the comments in 2 and 3 too?
|
I did some RTFS and it looks like printing comments is hardcoded for the most part.
(1) ssh-keygen prints comments like comment ? comment : "no comment" so that's where the "no comment" comes from.
(2) ssh-keygen checks for presence of test.pub by itself, it opens and validates the file even though it was not given on the command line. And then it sets comment like cp ? cp : filename so it defaults to the filename instead of "no comment".
So that is where the test.pub comment comes from. Move test.pub away and the result changes.
(3) it's completely hard-coded with no option to disable (short of changing the -m format from SSH2 to something else). You have to remove it with an external filter.
| How to completely disable SSH commenting? |
1,549,314,696,000 |
I have a RHEL 8.3 server and this is the content in the /etc/ssh folder:
[root@192 ssh]# pwd
/etc/ssh
[root@192 ssh]# tree -a
.
├── moduli
├── ssh_config
├── ssh_config.d
│ └── 05-redhat.conf
├── sshd_config
├── ssh_host_ecdsa_key
├── ssh_host_ecdsa_key.pub
├── ssh_host_ed25519_key
├── ssh_host_ed25519_key.pub
├── ssh_host_rsa_key
└── ssh_host_rsa_key.pub
1 directory, 10 files
[root@192 ssh]#
I found that when I ssh to this server from server1, the RSA public key (ssh_host_rsa_key.pub) was added in server 1's ~/.ssh/known_hosts file. But when I try another server server2, the ECDSA public key (ssh_host_ecdsa_key.pub) was added to ~/.ssh/known_hosts. Why the difference? What determines which public key will be used?
|
In the SSH protocol, the algorithms used for the cipher, MAC, key exchange, host key, and public key can be independently negotiated. In most cases, the algorithm selected is the first of the client algorithms that the server also supports.
Typically, a server has multiple host keys, and the choice of host key used is dependent on the algorithm negotiated. The latest versions of OpenSSH prefer Ed25519 keys, and before that, preferred ECDSA keys. However, OpenSSH has a special rule that if no special configuration of the host key is used and at least one host key is known in the known hosts file, then it will rewrite the preferred client algorithms to prefer the host keys that it knows about. This means that users won't see host key warnings if the server adds a new host key.
As mentioned, typically Ed25519 and ECDSA keys are preferred. However, OpenSSH recently dropped support for automatically using RSA with SHA-1 (the ssh-rsa signature algorithm, which is insecure), while it still supports RSA with SHA-2 (rsa-sha2-256 and rsa-sha2-512). Sometimes people choose to re-enable the ssh-rsa algorithm in the configuration despite the known security risks, and the typical pattern that people use for that puts the algorithm at the front of the list. Hence, it is possible that on that system, such a configuration was enabled in ~/.ssh/config or /etc/ssh/ssh_config, leading to preferring the RSA key.
| Which public key will be added into my ~/.ssh/known_hosts? |
1,549,314,696,000 |
I'd like to launch neofetch (a small utility that displays a banner) each time I log into a remote server via OpenSSH. So, I just added /usr/bin/neofetch into my ~/.ssh/rc file, and it works fine.
The problem is that ~/.ssh/rc is also parsed when I scp into the server. A complete scp command works just fine, there is however a problem when I try to use the autocomplete feature of scp, when I type <Tab><Tab> so it displays the files/folders available on the remote server, example :
$ scp remote-host:/t <TAB><TAB>
\\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\`\\\"\\\"\\\"\\\
\\\ \\\$\\\$\\\:\\\ \\\ \\\ \\\ \\\ \\\ \\\$\\\$.\\\ \\\ \\\ ^[\\\[0m^[\\\[31m^[\\\[1m-^[\\\[0m^[\\\[1m\\\ \\\ \\\ \\\ \\\,d\\\$\\\$\\\'\\\
\\\ \\\ \\\ \\\ \\\ \\\`\\\$\\\$b.\\\
\\\ \\\,\\\$\\\$P\\\'\\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\`\\\$\\\$\\\$.\\\
\\\ \\\$\\\$P\\\ \\\ \\\ \\\ \\\ \\\ d\\\$\\\'\\\ \\\ \\\ \\\ \\\ ^[\\\[0m^[\\\[31m^[\\\[1m\\\,^[\\\[0m^[\\\[1m\\\ \\\ \\\ \\\ \\\$\\\$P\\\
\\\'\\\,\\\$\\\$P\\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\,ggs.\\\ \\\ \\\ \\\ \\\ \\\`\\\$\\\$b\\\:\\\
\\\ \\\$\\\$\\\;\\\ \\\ \\\ \\\ \\\ \\\ Y\\\$b._\\\ \\\ \\\ _\\\,d\\\$P\\\'\\\
^[\\\[0m^[\\\[1m\\\ \\\`\\\$\\\$b\\\ \\\ \\\ \\\ \\\ \\\ ^[\\\[0m^[\\\[31m^[\\\[1m\\\"-.__\\\
^[\\\[0m^[\\\[1m\\\ \\\ \\\`Y\\\$\\\$\\\
(...)
Usually $ scp remote-host:/t <TAB><TAB> shows me the files/folders starting with /t (for example /tmp), but now it executes the neofetch banner.
Is there a way to distinguish $ ssh from $ scp in ~/.ssh/rc (to launch neofetch only when I ssh into the server, not when I scp into it) ?
Note : I don't want to launch neofetch each time I launch bash, nor each time I launch a login shell, so putting it in /etc/bash.bashrc or in /etc/profile is not an option. I only want to launch it after an SSH connection.
I did some research and tried a few things :
Inspired by this post, I tried :
if [ -t 0 ]; then /usr/bin/neofetch; fi
and
if tty > /dev/null; then /usr/bin/neofetch; fi
But it's not working (neofetch is never launched, not even after an $ ssh)
Inspired by that post, I also tried to use the $- environment variable to distinguish between interactive and non interactive sessions, but it doesn't work either, because ~/.ssh/rc is parsed by dash, not by bash (and $- is a bash variable)
I found however a working solution (well, sort of...). It was inspired by this post :
On the server, in ~/.ssh/rc, I put :
if [ ! "$LC_SCP" = "yes" ]; then /usr/bin/neofetch; fi
On the client, I have to set an LC_SCP environment variable before the $ scp :
$ export LC_SCP=yes
$ scp -o SendEnv=LC_SCP remote-host:/t<TAB><TAB>
(works, doesn't launch neofetch)
It works, but it's cumbersomee. Isn't there a better way to distinguish between ssh and scp sessions in ~/.ssh/rc ?
|
The environment variable SSH_TTY seems to be set only when sshing, not when scping. So the following suffices (at least in my testing):
if [ -n "$SSH_TTY" ]; then /usr/bin/neofetch; fi
(For what it's worth, I guessed this by looking at the output of env | grep -i ssh.)
| how to distinguish ssh from scp in ~/.ssh/rc? |
1,549,314,696,000 |
I have an SFTP server where I need to restrict users with specific IP addresses or ranges.
To achieve this, I had been appending AllowUsers entries to the sshd_config file like below and there are 180 such entries on the same line:
AllowUsers user1 user2 user3@ipaddress user4@ipaddress/n user5@ipaddres user5@address user5@address
and so on.
The problem is, the server's ssh service has been going down lately. And upon checking the server messages log, the error that causes the service failure is Line 143 too long. Line 143 is the AllowUsers line in my config file. The service seems to go down once the number of entries touches 184.
It seems like adding any more AllowUsers entries is not possible. Is there any kind of limit to the number of entries for AllowUsers?
Please urgently help me out with a solution. I don't think the AllowGroups is an option for me because I need to restrict each user with a different set of IPs.
|
Thanks a lot to those who put up their inputs here :)
I upgraded my OpenSSH and the limit restriction mentioned in my question is no more an issue now.
I followed the below blogs to complete and troubleshoot my OpenSSH upgrade. I was doing it on Amazon Linux. However, I believe this should work on centos as well.
https://www.tecmint.com/install-openssh-server-from-source-in-linux/
https://blog.jonkimi.com/2020/04/17/Upgrade-openssh-server-on-Ubuntu/
http://blog.chinaunix.net/uid-28813320-id-5786956.html
| Is there a limit to the number of user entries in AllowUsers that can be given in sshd_config file in Linux? |
1,549,314,696,000 |
Imagine the following scenario:
"Client" and "Connected" both exist on a network. A third computer, "Isolated," is not on any network but exposes a console over a serial port that can be read by Connected.
I sit at "Client" and I can access "Connected" from "Client" over ssh.
My goal is to get to "Isolated" as seamlessly as possible. I guess I could get a terminal on "Connected" and then use exec to talk to the console on "Isolated", but this seems rather clumsy. I'm sure many people have faced a similar scenario before, so what is the correct way to do this?
|
From a comment:
I'm using ssh between the "Client" and the "Connected" computer. Usually, the back end of ssh opens up a shell on the local tty at "Connected." I suspect that there might be a way to ask it to open up the remote console instead, and save me from having to type screen /dev/ttyUSB0 on the "Connected" host.
The ssh command by default opens a shell on the remote system, but you can have it run other commands. In this case, it seems like what you want is something like:
ssh connected screen /dev/ttyUSB0
... which you could put in a script or an alias on "Client".
| How to Configure OpenSSH Server to connect to an isolated computer's console via a serial port? |
1,549,314,696,000 |
I have many servers that shares a common TrustedUserCAKeys. I want to sign a user certificate so it grants some access on specific servers instead of all of them.
For example, the following command generates a certificate that can be used to log in as root on all servers:
ssh-keygen -s ca -I example -n root id_rsa.pub
I tried the following command, but it generates a certificate that's ... useless.
ssh-keygen -s ca -I example -n root@server1 id_rsa.pub
I intended to generate a certificate that can only sign in as root on server1, but not root on any other server. I've made sure that server1 is the FQDN on that server (or the complete content of /etc/hostname). Is there a way to achieve this without touching sshd_config on any host?
|
Without changing the sshd_config file, the answer is generally no. The mechanism to pull this off is to setup an AuthorizedPrincipalsFile (or AuthorizedPrincipalsCommand). Without this directive in sshd_config, the default behavior is that the username for the authentication attempt must be listed literally as one of the principals embedded in the certificate. This is why 'root' works, but 'root@server1' does not.
In order to make a certificate using 'root@server1' work (without adding entries into /root/.ssh/authorized_keys), you would need to configure an AuthorizedPrincipalsFile for the root user (later OpenSSH versions permit this directive inside a Match block), and list 'root@server1', and do something similar on other servers. You can also extend this to permit certificates applicable to groups of servers, like 'root@dev' or even 'root@*', as long as each appropriate flavor is listed as a principal in the AuthorizedPrincipalsFile.
Another way of implementing this, is to explicitly list the CA key and allowed principals in the .ssh/authorized_keys file, using both the cert-authority and principals= options. These are covered in the sshd man page description of the Authorized_Keys File Format.
| SSH User CA: Sign a user certificate with selected hosts instead of all hosts? |
1,549,314,696,000 |
Ubuntu 18.04.3 LTS (bionic) have OpenSSH server version 7.6p1 but that release is 2 years old by now. On my local Arch Linux machine I'm running 8.0p1 but Ubuntu naturally have slower pace.
The network analysis tool we use suggests upgrading the OpenSSH server to a newer version since it finds a few medium threats when testing the server. Since we are on the latest LTS release of Ubuntu we should be in the same situation as a huge portion of the servers on the Internet. How would you handle a situation like this? And from where would you install the update?
I have not been able to find a PPA for it, and that is maybe not the best source for critical components like this one.
The Ubuntu server I want to install version 8.0p1 on is a remote machine that I do not want to become locked out from so I want to experiment as little as possible.
|
How would you handle a situation like this? And from where would you install the update?
Supported Ubuntu LTS versions provide relevant security fixes to older versions, usually backported to the version shipped in the release. In case a vulnerability is fixed, installing the updated version from Ubuntu's repository is sufficient.
For any specific issue you can check the package changelog or general security notices. How long each Ubuntu release is supported is described on Ubuntu Releases page.
| Install openssh-server 8.0p1 on Ubuntu 18.04.3 LTS |
1,568,391,724,000 |
I have an FTP server that allows only SFTP connection – and only via password.
I have a list of files on the server - hundreds and thousands of files in many directories. And the directories contain a loooot of files we don't need. So, I have to fetch files on-by-one, controlled by the list.
The way I hoped to use is to create a script with a list of
get -p source_file dest.dir
commands – and feed it to the sftp command. But when I connect to the server in interactive mode, I cannot make sftp to consume the list.
The batch mode of sftp demands the remote machine to provide non-password identification.
What is the way to get files by list?
|
You can provide the commands to sftp without the batch mode using an input redirection:
sftp [email protected] < commands.txt
This way you can still use an interactive password authentication.
$ sftp [email protected] < commands.txt
[email protected]'s password:
Connected to [email protected].
sftp> get -p source_file dest
Fetching /path/source_file to dest
/path/source_file 100% 9474 975.4KB/s 00:00
sftp>
| Provide get commands to SFTP from a script file but keep interactive password login |
1,568,391,724,000 |
The server is running macOS Mojave 10.14.4. I'm unable to get the SSH daemon to start. After logging in locally, I run:
$ launchctl list | grep ssh
- 0 com.openssh.ssh-agent
$ ps -A | grep ssh
1483 ?? 0:00.00 ssh-agent -s
8483 ?? 0:00.00 ssh-agent
The service is not active. To resolve this, I've tried:
$ sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
$ sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
$ sudo launchctl stop com.openssh.sshd
$ sudo launchctl start com.openssh.sshd
$ eval `ssh-agent -s`
Agent pid 9055
I'm not having any luck. The last thing I attempted before having to take a break from trying to solve this issue was:
$ /usr/sbin/sshd -d
debug1: sshd version OpenSSH_7.9, LibreSSL 2.7.3
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
sshd: no hostkeys available -- exiting.
I then ran $ ssh-keygen -A but still receive the same message.
|
For enabling the SSH service/daemon in MacOS do:
sudo systemsetup -setremotelogin on
For disabling the SSH service do:
sudo systemsetup -setremotelogin off
For checking whether it is on or off:
sudo systemsetup -getremotelogin
(Tested with Mojave)
Btw, sshd has to be run as root, not as you are running it. It has to be:
sudo /usr/sbin/sshd -d &
| Can't get SSH daemon running on macOS |
1,568,391,724,000 |
Very similar to Failed to open config file '/dev/fd/63', error: No such file or directory for wpa_supplicant except for the fact that I am running as root.
bash-4.4# autossh -v -M 0 -4 -o StrictHostKeyChecking=no -F <(echo "$VA_SOCKS_PROXY_SSH_CONFIG") -i <(echo "$VA_SOCKS_PROXY_PRIVATE_KEY") socks -D "0.0.0.0:2001" -N
Warning: Identity file /dev/fd/62 not accessible: No such file or directory.
OpenSSH_7.9p1, OpenSSL 1.1.1a 20 Nov 2018
Can't open user config file /dev/fd/63: No such file or directory
The output is failing in two places. If I do a ssh-add <(echo "$VA_SOCKS_PROXY_PRIVATE_KEY") it works fine. Seems like the pipe is being read possibly by autossh first, then being read a second time by ssh (or vice versa) and therefore it is gone the second time.
UPDATE1: it appears running with just ssh reproduces same errors, so my hypothesis above is invalidated.
UPDATE2: This comment says:
It seems ssh simply doesn’t support that mode of operation, because it closes FDs 3 and higher very early in main()
|
It appears that ssh closes all file descriptors early on in main() and as such does not support process substitution.
/*
* Discard other fds that are hanging around. These can cause problem
* with backgrounded ssh processes started by ControlPersist.
*/
closefrom(STDERR_FILENO + 1);
Sources
https://github.com/openssh/openssh-portable/blob/master/ssh.c#L621
https://github.com/openssh/openssh-portable/blob/c327813ea1d740e3e367109c17873815aba1328e/ssh.c#L621 (archive link)
| (root) Warning: Identity file /dev/fd/62 not accessible: No such file or directory |
1,568,391,724,000 |
Is it possible to restrict the use of CA certificates to specific users/principals/groups?
The use case is that I'd like to have 2 CA certificates. One would be used as part of an automated system to sign user keys. If this certificate were to be compromised, I want to be sure that it couldn't be used to allow someone to log into an admin account.
The other CA certificate would obviously be more securely stored (airgapped etc.) and used for admin accounts.
|
Based on Ulrich Schwarz's comment:
If I add normal users to an endusers group, then I can set the sshd_config like this:
TrustedUserCAKeys /etc/ssh/admin_ca.pub
Match Group endusers
TrustedUserCAKeys /etc/ssh/user_ca.pub
This results in the user_ca only being accepted for users in the endusers group, while the admin_ca can be used for any user.
| Restrict SSH CA certificates to specific users/groups |
1,568,391,724,000 |
I'm following this tutorial to validate a SSH server, in theory I should use a private key provided by an authoring server to sign the SSH pub key, but I don't understand the role of the -I <key_id> option and what value should it have:
ssh-keygen -s server_ca -I host_sshserver -h -n sshserver.example.com /etc/ssh/ssh_host_rsa_key.pub
Thanks in advance.
|
Excerpts from man ssh-keygen:
-I certificate_identity
Specify the key identity when signing a public key. Please see the CERTIFICATES section for details.
CERTIFICATES
ssh-keygen supports signing of keys to produce certificates that may be used for user or host authentication. Certificates consist of a public key, some
identity information, zero or more principal (user or host) names and a set of options that are signed by a Certification Authority (CA) key. Clients or
servers may then trust only the CA key and verify its signature on a certificate rather than trusting many user/host keys. Note that OpenSSH certifi‐
cates are a different, and much simpler, format to the X.509 certificates used in ssl(8).
ssh-keygen supports two types of certificates: user and host. User certificates authenticate users to servers, whereas host certificates authenticate
server hosts to users. To generate a user certificate:
$ ssh-keygen -s /path/to/ca_key -I key_id /path/to/user_key.pub
The resultant certificate will be placed in /path/to/user_key-cert.pub. A host certificate requires the -h option:
$ ssh-keygen -s /path/to/ca_key -I key_id -h /path/to/host_key.pub
The host certificate will be output to /path/to/host_key-cert.pub.
It is possible to sign using a CA key stored in a PKCS#11 token by providing the token library using -D and identifying the CA key by providing its pub‐
lic half as an argument to -s:
$ ssh-keygen -s ca_key.pub -D libpkcs11.so -I key_id user_key.pub
In all cases, key_id is a "key identifier" that is logged by the server when the certificate is used for authentication.
Certificates may be limited to be valid for a set of principal (user/host) names. By default, generated certificates are valid for all users or hosts.
To generate a certificate for a specified set of principals:
$ ssh-keygen -s ca_key -I key_id -n user1,user2 user_key.pub
$ ssh-keygen -s ca_key -I key_id -h -n host.domain host_key.pub
Additional limitations on the validity and use of user certificates may be specified through certificate options. A certificate option may disable fea‐
tures of the SSH session, may be valid only when presented from particular source addresses or may force the use of a specific command. For a list of
valid certificate options, see the documentation for the -O option above.
Finally, certificates may be defined with a validity lifetime. The -V option allows specification of certificate start and end times. A certificate
that is presented at a time outside this range will not be considered valid. By default, certificates are valid from UNIX Epoch to the distant future.
For certificates to be used for user or host authentication, the CA public key must be trusted by sshd(8) or ssh(1). Please refer to those manual pages
for details.
Note:
In all cases, key_id is a "key identifier" that is logged by the server when the certificate is used for authentication.
And from your link it states:
-I: This is a name that is used to identify the certificate. It is used for logging purposes when the certificate is used for authentication.
When using certificates for authentication, these have keys to identify the the particular certificate of authentication. This is given any name you like I could call mine my-new-cert-id and the certificate will be built with that id and used to access my authentication certificate.
Note that in that link you provided two different -I names were used so choose that which you like.
Role of -I: ssh-keygen supports signing of keys to produce certificates that may be used for user or host authentication. Used when you need to use certificates for authentication.
Value of -I:: Any name of your liking
| What the -I certificate_identity ssh-keygen option is for? |
1,568,391,724,000 |
I'm looking for a way to set a specific SSH key while logging to a remote host with a particular username. Is this possible within the SSH config file?
For example:
Use key "id_rsa-test" for username "testuser":
ssh testuser@host1
ssh testuser@host2
ssh testuser@host3
Use key "id_rsa" for all other users.
ssh root@host1
ssh admin@host2
ssh [email protected]
Is there a way to configure this?
|
Thank you @xhienne (comment link) for your suggestion.
Adding the following to ssh_config appears to have solved the problem:
Match User testuser
IdentityFile ~/.ssh/id_rsa-test
This block should be placed above Host * to send id_rsa-test ahead of id_rsa for testuser.
| Use X SSH key when logging in to Y remote user? |
1,568,391,724,000 |
When I log into a remote centos 7 server as root, I am able to see the sshd logs by typing journalctl _COMM=sshd in the terminal. But the logs are massive. How can I download all the logs into a format such as a text file for analysis on my local machine?
|
Redirect them out to a file:
journalctl _COMM=sshd > sshd_logs
| downloading sshd logs from remote centos 7 server |
1,568,391,724,000 |
I got a nexenta system,
I updated openssl to 1.0.1j, which I compiled from source code.
I updated openssh to 6.7, from source code as well, and I get this:
root@cteraportal:/root# openssl version
OpenSSL 1.0.1j 15 Oct 2014
root@cteraportal:/root# ssh -V
OpenSSH_6.7p1, OpenSSL 0.9.8k 25 Mar 2009
Should I expect the OpenSSL version to be updated on ssh?
|
Why can't the OpenSSH configure script detect OpenSSL explains the possible cause that might have occured in your case.
Several reasons for problems with the automatic detection exist.
OpenSSH requires at least version 0.9.5a of the OpenSSL libraries.
Sometimes the distribution has installed an older version in the
system locations that is detected instead of a new one installed.
The OpenSSL library might have been compiled for another CPU or
another mode (32/64 bits). Permissions might be wrong.
The general answer is to check the config.log file generated when running the OpenSSH configure script. It should contain the detailed information on why the OpenSSL library was not detected or considered incompatible.
However, in your case I find this information as well.
Portable OpenSSH now requires openssl 0.9.8f or greater. Older
versions are no longer supported.
So as per your ssh -V command output, I think you are having a greater version than that is required.
| update openssh and openssl on solaris |
1,568,391,724,000 |
I really really hope I'm wrong here, but it seems that Debian 11 has a vulnerable version of OpenSSH.
My OpenSSH banner reports my OpenSSH version is:
8.4p1 Debian 5+deb11u1
I checked with sshd and it reports the same version.
According to this CVE-2023-38408 ANY version before 9.3p2 is vulnerable.
I tried sudo apt update && sudo apt full-upgrade but it did not update the OpenSSH version..
|
At the time of writing (17 August 2023) the page of CVE-2023-38408 on the Debian security tracker says that:
Debian 10 (buster, security channel) is fixed
Debian 10 (buster) is vulnerable
Debian 11 (bullseye) is vulnerable
Debian 12 (bookworm) is vulnerable
Debian 13 (trixie) is fixed
Debian Unstable (sid) is fixed
There is also a note saying that:
[...]
Minor issue; needs specific conditions and forwarding was always subject to caution warning
[...]
Exploitation requires the presence of specific libraries on the victim system.
Remote exploitation requires that the agent was forwarded to an attacker-controlled
system.
| Are all Debian 11 systems automatically vulnerable to CVE-2023-38408? |
1,568,391,724,000 |
I use keepassxc (my password manager) to manage my ssh keys. This means the keys are stored within the database (not stored on disk in a traditional way). When I unlock my password database, all keys are added to the agent. However, with a growing list of ssh keys, I get the problem that ssh tries all the keys in the agent, which results in Too many authentication failures if the remote host allows less authentication tries than i have ssh keys (and the particulary ssh key is far back in the list).
Is there a way to tell ssh: "for this host, use the key with fingerprint xyz, fetch it from the agent"? Alternatively pubkey xyz, but I can't use the IdentityFile option (and IdentitiesOnly yes), since I don't want to store my private keys on disk.
|
but I can't use the IdentityFile option (and IdentitiesOnly yes), since I don't want to store my private keys on disk.
You can. Store the corresponding public key(s) on disk. Use IdentitiesOnly yes and the IdentityFile option and point to the right public key. This solution is not explicitly explained in man 5 ssh_config where it describes IdentityFile, nevertheless it should work. It is mentioned in man 1 ssh where it describes -i [emphasis mine]:
-i identity_file
Selects a file from which the identity (private key) for public key authentication is read. You can also specify a public key file to use the corresponding private key that is loaded in ssh-agent(1) when the private key file is not present locally.
| manage many ssh keys via ssh-agent |
1,568,391,724,000 |
I'd like to know why my known_hosts file doesn't seem to be checked correctly while using SSH. In short, my guess is that my SSH client is checking /dev/null instead of the known_hosts file. Details on how I guessed that are written below.
For my example, I'm logging in from a node named mars into a client node named saturn. I can get into saturn after setting up the public and private keys, but I get this warning:
root@mars# ssh saturn
Warning: Permanently added 'saturn,10.30.3.3' (ECDSA) to the list of known hosts.
When I logged out and logged in to the same saturn node, I got the same warning message. It doesn't matter how many times I log out and log back in, I get this message. I don't want to suppress the warning. I want to know why this warning keeps appearing. I checked if my known_hosts file in the mars node has the saturn's ECDSA key by doing the following, but I get an error:
# ssh-keygen -F saturn
do_known_hosts: hostkeys_foreach failed: No such file or directory
I wondered if the known_hosts file is not checked correctly while using the SSH client, so logged in with the verbosity flags to check where things went wrong. Below is a truncated output:
root@mars# ssh -vvv saturn
.
.(truncated)
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:nkvxyuLtlDdO8pAycafcfqSPE7OUWgN6Z++Aia/Cygg
debug3: hostkeys_foreach: reading file "/dev/null"
debug3: hostkeys_foreach: reading file "/dev/null"
Warning: Permanently added 'saturn,10.33.3.3' (ECDSA) to the list of known hosts.
.
.(truncated)
So, it seems like my SSH client on mars is looking into /dev/null for the known hosts key, instead of /root/.ssh/known_hosts.
I wanted to see what a "good" behavior looks like, so I used SSH on a different pair of servers (here named earth and neptune) that I already know does not give me the Warning: Permanently added message. I've turned on verbosity and I'm only showing a portion of the log messages. Logging in from earth to neptune gives:
root@earth# ssh -vvv neptune
.
. (truncated)
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:qo7vcBwG53p/9MlaTIQJbMZ8Wgf6QxiCJLR1jUiblQ8
debug3: hostkeys_foreach: reading file "/root/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /root/.ssh/known_hosts:9
debug3: load_hostkeys: loaded 1 keys from saturn
debug3: hostkeys_foreach: reading file "/root/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /root/.ssh/known_hosts:3
debug3: load_hostkeys: loaded 1 keys from 10.33.9.10
debug1: Host 'neptune' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:9
.
.(truncated)
From the above, I can see that earth correctly checks /root/.ssh/known_hosts. Another confirmation that the key is found in known_hosts in this "good" scenario:
root@earth# ssh-keygen -F neptune
# Host neptune found: line 7
In summary, does anyone know why the Warning message keeps appearing, and if the SSH client is indeed checking /dev/null instead of known_hosts? If my guess is correct, how might the client be fixed so that the message doesn't reappear?
I'm using Ubuntu 18.04 and this SSH client version on all nodes:
root@mars:~# ssh -V
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017
Thanks in advance for any help.
|
The only explanation that comes to mind is that the SSH client configuration either on this machine or on this account has been modified to not remember known public keys in a known_hosts file. Check the settings for GlobalKnownHostsFile and UserKnownHostsFile in /etc/ssh/ssh_config, /etc/ssh/ssh_config.d/* and ~/.ssh/config.
This may have been done to increase privacy, so that other administrators on the machine (or people who manage to compromise the machine or its backups in the future) can't see where you've connected to unless they spy on the connection. For the known_hosts file, this is not a very good compromise between privacy and security: having to check the peer's public key manually each time is error-prone (in addition to being inconvenient). Turning on the HashKnownHosts option gives a decent amount of privacy with a decent amount of functionality: with this option turned on, it's impossible to directly list the entries in a known_hosts file, all you can do is guess what the entry might be and check your guess (and each check is somewhat costly, so you can't brute-force a very large number of potential server names).
| SSH client seems to be checking '/dev/null' instead of 'known_hosts' file when checking remote server's ECDSA key |
1,568,391,724,000 |
Background
I use a 4096-bit RSA key-pair for authorizing access to my server. By ssh_config files I am referring to ~/.ssh/config and /etc/ssh/ssh_config.
Here's what my ~/.ssh/config looks like:
Host gg-root
HostName 172.47.95.122
Host ss-root
HostName 172.47.95.123
# Common for my servers
Host gg-root ss-root
User root
Port 32001
IdentitiesOnly yes
IdentityFile ~/.ssh/id_rsa_bull
# Common for all
Host *
AddKeysToAgent yes
Now, I can simply connect to my server via SSH with the following (without any further configuration):
ssh gg-root
ssh ss-root
Thing is, I need to add the private key ~/.ssh/id_rsa_bull to the system's SSH agent to make it easily available to other apps like FileZilla which I use for SFTP. (Esp. because I don't like that FileZilla needs an unencrypted private key as .ppk.)
So, I either run this command each time:
ssh-add ~/.ssh/id_rsa_pepper
Or have this in my ~/.profile:
ssh-add ~/.ssh/id_rsa_pepper > /dev/null 2>&1
Question
When I add the key to the system's SSH agent using ssh-add, does it honor the declarations I've made in ssh_config file(s)? Specifically, does it make sure that ~/.ssh/id_rsa_pepper is only used for 172.47.95.{122,123}?
Based on how I interpreted what I read, I believe it should. If I am wrong, please enlighten me as to how I should go about adding a private key to the system's SSH agent where the said private key is only used for stated hosts?
EDIT: Based on Answer
This is what my ~/.ssh/config looks like now:
Host gg-root
HostName 172.47.95.122
Host ss-root
HostName 172.47.95.123
# Common for my servers
Host gg-root ss-root
User root
Port 32001
IdentityFile ~/.ssh/id_rsa_bull
# Common for all
Host *
AddKeysToAgent yes
IdentitiesOnly yes
|
ssh-add does not honour the configuration file. It just adds the key to the agent.
The ssh client would try to use the key ~/.ssh/id_rsa_bull when connecting to either of gg-root or ss-root (due to the IdentityFile configuration). If that key is available in the agent, then it will be used from there, otherwise the key will be used from file (and a password may have to be provided if the key has one associated with it).
The keys in the agent would also be used when connecting to any other host not configured with a specific IdentityFile in ~/.ssh/config. This means that the configuration restricts the keys used for authenticating with particular hosts, but the shown configuration does not stop the "bull key" from being used with other hosts.
| Does ssh-add honor the declarations made in ssh_config file(s)? |
1,568,391,724,000 |
I have a server set up to require public-key authentication for ssh access using a key with a password. Is there a way to set up a password-less key that will only be allowed when executing rsync over ssh, while still requiring the key and password for all other ssh access?
|
Create a separate RSA key just for rsync to use. Do not put a passphrase on that key. Give it a unique name, such as id_rsa_rsync for the private key and id_rsa_rsync.pub for the public key.
On the server, install the public key on a new line of ~/.ssh/authorized_keys, like this:
(server)$ cat << EOF >> .ssh/authorized_keys
command="rsync",no-pty,no-port-forwarding (paste your public key here)
EOF
Check the resulting file to make sure it looks sort of like this:
(server)$ tail -1 .ssh/authorized_keys
command="rsync",no-pty,no-port-forwarding ssh-rsa AAAAB3..blah..blah..HhcvQ== [email protected]
When you want to rsync from your local machine to the server, you will need to add -e 'ssh -i ~/.ssh/id_rsa_rsync' to tell rsync to use the new key you just set up:
rsync -av -e 'ssh -i ~/.ssh/id_rsa_rsync' local/files* server:/remote/path/
With some clever entries in your ~/.ssh/config file, you can simplify the rsync command line:
# this entry is used for normal logins to "server":
Host server
IdentityFile ~/.ssh/id_rsa
# this entry is used for rsyncing to "server" without a passphrase:
Host server-rsync
Hostname server
IdentityFile ~/.ssh/id_rsa_rsync
The Hostname server line needs to specify a valid DNS name or /etc/hosts entry. With that config entry in place, your rsync command line becomes just:
rsync -av local/files* server-rsync:/remote/path/
| Passwordless rsync while requiring key and password for all other access |
1,568,391,724,000 |
I'm trying to use ssh-copy-id in order to copy my id_rsa.pub into ~/.ssh/authorized_keys in remote host.
I execute the following:
$ ssh-copy-id remoteuser@remotehost
But I have the following error:
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
remoteuser@remotehost's password:
rootsh: bad characters in arguments
|
It looks like this server is using something called rootsh. This tutorial titled: How to track Linux Shell Users activity? covers it too.
rootsh: bad characters in arguments
In these types of scenarios, you'll likely have to ssh to the server and then copy/paste the public portion of your SSH key-pair into the user account's $HOME/.ssh/authorized_keys file by hand.
NOTE: your SSH key will typically be here on your local system: ~/.ssh/id_rsa.pub. So open it in an editor, copy it to your clipboard, then ssh to the remote server and open the authorized_keys file (above) and paste the clipboard into it and save it.
| ssh-copy-id returns error "rootsh: bad characters in arguments" |
1,568,391,724,000 |
Other people log into my Raspberry Pi via SSH. It runs Ubuntu Mate 16.04 with OpenSSH. I want to disable some of the accounts but not delete them.
Now, I could just delete the passwords (which obviously has the disadvantage that a way to set the password, again, has to be found, unless I manually change the contents of the shadowfile which feels like a really bad idea) of the accounts I want to disable and rename their ~/.ssh/authorized_keys files to prevent them from logging in. However, I'd like there to be an error message on their consoles when they attempt to log in, describing why I disabled their accounts. The message is the same for all disabled accounts.
There seems to be an easy way to disable SSH login for entire groups which means that I can just add the users I want to disable to a certain group and disable SSH login for that group. However, this doesn't print them the message I want to be shown on their consoles.
I know how to put a message on the user's console once they logged in. But the goal, here, of course is that they don't get that far.
Because the users don't have physical access to my Raspberry Pi, I don't care whether the accounts are entirely disabled or it's just not possible to log into them via SSH. I don't care about the user switching to a different account via su later on because only root and my user account can do this, anyways.
|
Well ... one of all the possible answers is to change the shell of the user to /sbin/nologin. It will allow to authenticate and then say
This account is currently not available.
(if the /sbin/nologin is in /etc/shells)
Otherwise you can use similar approach as the linked article with ForceCommand:
Match Group disabled_group # or User disabled_user
ForceCommand echo "This account is disabled"
| Disable accounts and print info message on attempted login |
1,568,391,724,000 |
I am trying to use ssh supporting GSSAPI with KeyExchange protocol with some servers that authenticate using kerberos. I have installed aur/openssh-gssapi. The problems is after getting the key from krb-server using kinit, when I ssh to the server it fails with this message:
Unable to negotiate with blah.blah: no matching key exchange method found. Their offer: gss-gex-sha1-toWM5Slw5Ew8Mqkay+al2g==,gss-group1-sha1-toWM5Slw5Ew8Mqkay+al2g==,gss-group14-sha1-toWM5Slw5Ew8Mqkay+al2g==
It says that they offer: [the key exchange above], but I have its support in my offerings:
debug1: Offering GSSAPI proposal: gss-gex-sha1-toWM5Slw5Ew8Mqkay+al2g==,gss-group1-sha1-toWM5Slw5Ew8Mqkay+al2g==,gss-group14-sha1-toWM5Slw5Ew8Mqkay+al2g==,gss-gex-sha1-A/vxljAEU54gt9a48EiANQ==,gss-group1-sha1-A/vxljAEU54gt9a48EiANQ==,gss-group14-sha1-A/vxljAEU54gt9a48EiANQ==,gss-gex-sha1-bontcUwnM6aGfWCP21alxQ==,gss-group1-sha1-bontcUwnM6aGfWCP21alxQ==,gss-group14-sha1-bontcUwnM6aGfWCP21alxQ==,gss-gex-sha1-eipGX3TCiQSrx573bT1o1Q==,gss-group1-sha1-eipGX3TCiQSrx573bT1o1Q==,gss-group14-sha1-eipGX3TCiQSrx573bT1o1Q==
I wonder what could be the cause of this problem!?
Edit: since I didn't see the point I did not post the log output of ssh command but just in case I am going to paste it in here:
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: [email protected],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],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-rsa
debug2: kex_parse_kexinit: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1,[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1,[email protected],[email protected],[email protected],[email protected],hmac-md5,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: first_kex_follows 0
debug2: reserved 0
debug2: kex_parse_kexinit: gss-gex-sha1-toWM5Slw5Ew8Mqkay+al2g==,gss-group1-sha1-toWM5Slw5Ew8Mqkay+al2g==,gss-group14-sha1-toWM5Slw5Ew8Mqkay+al2g==
debug2: kex_parse_kexinit: null
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],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,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,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: first_kex_follows 0
debug2: reserved 0
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
Unable to negotiate with yada.yada: no matching key exchange method found. Their offer: gss-gex-sha1-toWM5Slw5Ew8Mqkay+al2g==,gss-group1-sha1-toWM5Slw5Ew8Mqkay+al2g==,gss-group14-sha1-toWM5Slw5Ew8Mqkay+al2g==
|
There is a bug in the patch in Arch Linux. They are setting the Kexs, but they are immediately overwritten by the other changes in the code:
The line
xasprintf(&myproposal[PROPOSAL_KEX_ALGS], "%s,%s", gss, orig);
should say
xasprintf(&options.kex_algorithms, "%s,%s", gss, orig);
From the brief check of the source against what we ship in Fedora.
Edit: Of course also this line:
orig = myproposal[PROPOSAL_KEX_ALGS];
should be
orig = options.kex_algorithms;
| Archlinux + GSSapi + kerberos |
1,568,391,724,000 |
I'm experimenting with Docker's Alpine Linux image and OpenSSH. The sshd_config file that ships with alpine has everything commented out by default. I only uncomment Port 22. I assume this is the most secure configuration (But would like some feedback on whether this assumption is correct).
I then run ssh-keygen -q to generate the user keys (For root) and ssh-keygen -A to generate the host keys. I then cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys so that I can log in with the key.
When I log in from the host with ssh localhost I get prompted to accept the host key and then I get in. So everything seems to be working fine. However if I try to connect from outside the docker conatainter / host I get prompted for a password. Should this happen? My assumption was that since I only configured the Port parameter everything else would be turned off including password authentication.
|
However if I try to connect from outside the docker conatainter / host I get prompted for a password. Should this happen? My assumption was that since I only configured the Port parameter everything else would be turned of including password authentication.
Yes. The password authentication is on by default, because it is sometimes the only method you can access newly installed servers. But you can simply turn it off using ChallengeResponseAuthentication no and PasswordAuthentication no in your sshd_config.
| Authentication methods allowed by default in OpenSSH on Alpine |
1,568,391,724,000 |
With the 7.0 release, OpenSSH disabled ssh-dss keys. The not-so-recommended workaround is to explicitly re-add DSA key support to .ssh/config, which will eventually be dropped by a later OpenSSH version:
PubkeyAcceptedKeyTypes=+ssh-dss
As I have deployed my DSA key to countless machines (and I do not have a full list of them, as known_hosts is hashed), I have to replace the old public user key whenever I encounter it on login.
Is it possible to make the OpenSSH client display a warning when I log in with an ssh-dss key?
|
There is no special mechanism in ssh to notify you that you use some key. It works or fails.
Differentiate the keys using passphrase
Only other idea that comes to my mind is differentiate between the keys using passphrase.
For example, have the RSA keys in ssh-agent or without passphrase and the DSA one with passphrase (and not in ssh-agent). It might warn you with passphrase prompt.
Not to use them
The easiest thing is not to add the above line into ssh_config and then you will see when you can't connect. Then you can use the options on command line for individual connections:
ssh -oPubkeyAcceptedKeyTypes=+ssh-dss host
| SSH: display warning when using (deprecated) ssh-dss key |
1,568,391,724,000 |
I regularly upload large amounts of data using SCP through my DSL upstream connection, which is limited to 1kbit/s. While I really want interactive SSH sessions to have highest priority, simply setting SSH to the highest priority renders the connection unusable during SCP uploads.
How can I differentiate between SSH and SCP for Quality of Service settings, especially in OpenWRT?
|
At least OpenSSH sets different TOS bits (0x16 for interactive sessions, 0x08 for bulk transfers), as discussed on quora.
This can be easily exploited using rules that match those bits. It seems the highest matching QoS takes effect, make sure not to have a general rule for port 22/SSH around: OpenWRT by default ships a rule matching SSH and DNS together. For there rules, I used the overlapping DSCP values of 0x04 and 0x02 as proposed in the quora post linked above.
config classify
option target "Priority"
option ports "22"
option dscp 0x04
option comment "ssh"
config classify
option target "Bulk"
option ports "22"
option dscp 0x02
option comment "scp"
For "naked" iptables setups, these are the resulting rules (the -m dscp --dscp 0x04 and -m dscp --dscp 0x02 arguments are the most interesting parts):
-A qos_Default_ct -p tcp -m mark --mark 0x0/0xf -m tcp -m multiport --ports 22 -m dscp --dscp 0x04 -m comment --comment ssh -j MARK --set-xmark 0x11/0xff
-A qos_Default_ct -p tcp -m mark --mark 0x0/0xf -m tcp -m multiport --ports 22 -m dscp --dscp 0x02 -m comment --comment scp -j MARK --set-xmark 0x44/0xff
Be sure to restart the SCP transfer after reloading the QoS settings using /etc/init.d/qos restart. QoS settings are only applied to new streams.
Before applying those rules (with a single SSH "priority" rule), I had a ping of around 200ms during SCP uploads; with the rule applied it came down to 70-100ms (compared to 30ms through an idle line).
| How to discriminate between SSH and SCP for QoS in OpenWRT (and other systems)? |
1,568,391,724,000 |
I'm completely at a loss as to what is preventing my local machine from authenticating the connection that is being forwarded from the remote server.
I've read a ton of the posts on here regarding this and man, I swear I've tried damn near everything.
The guide I've been following can be found here: http://www.zeespencer.com/articles/building-a-remote-pairing-setup/
Basically where I'm stuck at is in forcing passwordless authentication. If I allow passwords in sshd_config, when I connect to pair@pair-server I am prompted for my local user password and am able to login remotely, so I am being forwarded. But, as soon as I turn it off, I get the following
λ ssh pair@pair-server
Permission denied (publickey).
Connection to pair-server closed.
Verbose output here: https://gist.github.com/anonymous/0c2b3892596d5ded6abb
I currently have my local user key.pub in pair@pair-server's .ssh/authorized_keys which are command directed to ssh back to localhost. pair@pair-server has it's own key, on my computer I've added pair@pair-server's key.pub to .ssh/authorized_keys.
Seemingly relevant lines in sshd_config:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
PermitEmptyPasswords no
PasswordAuthentication no
UseLogin no
account and session settings in /etc/pam.d/sshd on pair-server:
account required pam_nologin.so
account include password-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session required pam_selinux.so open env_params
session optional pam_keyinit.so force revoke
session include password-auth
password-auth configuration:
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required pam_env.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 500 quiet
auth required pam_deny.so
account required pam_unix.so
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 500 quiet
account required pam_permit.so
password requisite pam_cracklib.so try_first_pass retry=3 type=
password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
.ssh permissions:
node-v0.8.25|ruby-1.9.3-p392|~|
λ ls -lhd .ssh
drwx------ 2 dan dan 4.0K Jul 10 19:49 .ssh
OS:
λ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 13.04
Release: 13.04
Codename: raring
OpenSSH Client Version:
λ ssh -V
OpenSSH_6.1p1 Debian-4, OpenSSL 1.0.1c 10 May 2012
|
Thanks for trying to help everyone, really appreciate it. Anyways, it seems ssh-agent was the culprit. I forgot I have to check if there is previously spawned instances of it already running before spawning my own. I had something like 9 of them running. I don't know much bash, but here where the 3 lines I added to my .bashrc on the remote server that got it working:
pkill ssh-agent
exec "$(ssh-agent)"
ssh-add $HOME/.ssh/pair_key
| Unable to force passphraseless ssh authentication while port forwarding |
1,568,391,724,000 |
I'd like to wrap an insecure connection (this one: http://culturedcode.com/things/) with a secure tunnel, a bit like http://en.wikipedia.org/wiki/Stunnel does, just using UNIX tools.
What's the best way to intercept insecure traffic, encrypt it and deliver it to the insecure socket at the other end of the communication channel?
I am used to wrapping/tunnelling VNC connections using SSH port forwarding, how would you do something to the same effect with an application such as Things for Mac/iPhone? Namely: a generic application using known ports to exchange unencrypted data?
Bonus points for step-by-step instructions ;)
Thanks!
|
Have a look at ncat (which is part of nmap).
ncat -l 80 -c "ncat (ip-address) (port) --ssl"
For more information see: Using ncat to provide SSL-support to non-ssl capable software
| Wrapping socket connections |
1,568,391,724,000 |
I have an Ubuntu server and I want to log all SSH activity on my server.
For this, I found one good document here: How to log all Bash commands by all users on a server? I followed this document and enable the logging on the server. I log the commands with the following line:
export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"
It gives the log of all executed command on my server (locally executed and SSHed).I have attached the output of the same.
What I need is, In the log file there should be a username or the hostname and public IP address of the user who used to connect to my local server.
Does anybody have an idea about this?
Output log file:
Aug 7 11:03:34 local ajay: ajay [1906]: sudo rm -rf commands.log*
Aug 7 11:03:36 local ajay: ajay [1906]: ll
Aug 7 11:03:59 local ajay: ajay [1906]: sudo rm -rf messages*
Aug 7 11:04:19 local ajay: ajay [1906]: sudo rm -rf usercommands
Aug 7 11:04:49 local ajay: ajay [1906]: sudo rm -rf history.log
Aug 7 11:05:11 local ajay: ajay [1906]: ll
Aug 7 11:05:21 local ajay: ajay [1906]: cat commands.log
Aug 7 11:05:33 local ajay: ajay [1906]: cat commands.log
Aug 7 11:05:46 local ajay: ajay [1906]: sudo chmod -R 777 commands.log
Aug 7 11:05:48 local ajay: ajay [1906]: cat commands.log
Aug 7 11:06:19 local ajay: ajay [1906]: cat commands.log
|
The variable $SSH_CONNECTION gives you the ports and source/destination IP addresses used by the user connection. So add it as argument to your logger command.
As in:
export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$SSH_CONNECTION $(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"
For further details, have a look at What are SSH_TTY and SSH_CONNECTION?
As for the hostname, that is dependent on DNS resolution. You can always script for solving the reverse DNS of the logs. There is no directive I am aware of that solves directly to the DNS name.
| How to log all SSH activity on server with user's hostname or User name? |
1,568,391,724,000 |
In RedHat based distributions you can set the type of server private and public keys which the init script will automatically create, with the variable AUTOCREATE_SERVER_KEYS variable.
Can you do this in Debian and if yes, how?
|
In Debian, regenerating host keys can happen with:
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
| OpenSSH - automatic server private and public keys creation |
1,568,391,724,000 |
I currently have an sftp-only sshd service running as an unprivileged user that works fine. When adding
ChrootDirectory %h
to the separate user_sshd_config, the user is immediately disconnected after successfully authenticating with publickeys and the error log shows the following:
fatal: server lacks privileges to chroot to ChrootDirectory [postauth]
The target directory is owned by the user running the process.
Is it possible to run a chroot'd sshd service running as an unprivileged user, or does the service have to have root permissions to perform a chroot operation?
Let me know if more information is needed, but from what I can see, all relevant information has been provided.
|
Alas, chroot(2) must be called as root.
| Is it possible to chroot sftp service as unprivileged user? |
1,568,391,724,000 |
With OpenSSH, how can I log the fingerprints of the keys used for authentication?
I would like to log it in production, so it would be best if this wasn't just some debug setting or similar.
|
Yes, by setting LogLevel to VERBOSE, you would see logs like the following,
sshd[1199]: Connection from 192.168.56.1 port 45811
sshd[1199]: Found matching RSA key: XXXX
sshd[1199]: Postponed publickey for root from 192.168.56.1 port 45811 ssh2 [preauth]
sshd[1199]: Found matching RSA key: XXXX
sshd[1199]: Accepted publickey for root from 192.168.56.1 port 45811 ssh2
| Assuming sshd allows only public key authentication, how do I log the fingerprints? |
1,638,661,752,000 |
I want to open many tunnels at once, they all have the same long password.
With -f, i.e.,
ssh -fN -p 22 usr1@gate1 -L 10001:ip1:22
ssh -fN -p 22 usr2@gate2 -L 10002:ip2:22
...
ssh -fN -p 22 usrn@gaten -L 1000n:ipn:22
I can open the tunnels in background, which allows me to run them all together and then just type consecutively the password as many times as the number of tunnels I am opening (n).
Given that what I type is the same, I would like to find a way to type it just once, but still do it in a secure way.
|
I found the solution using https://stackoverflow.com/a/3980904/1424395 and https://unix.stackexchange.com/a/59632/269821
I use read -s to get the password into a variable, and then I use sshpass to pass the password to the ssh.
#!/usr/bin/env bash
# Read Password
echo -n Password:
read -s password
echo
sshpass -p $password ssh -fN -p 22 usr1@gate1 -L 10001:ip1:22
sshpass -p $password ssh -fN -p 22 usr2@gate2 -L 10002:ip2:22
...
sshpass -p $password ssh -fN -p 22 usrn@gaten -L 1000n:ipn:22
| Opening many tunnels typing the password only once (all accounts in gateways have the same pass) |
1,638,661,752,000 |
I'm connecting using OpenSSH to a Linux server where I have a tmux session where I do certain compiling work which takes a long time. Now I would like to be get right away a notification on my Linux client (the computer I'm connecting from) once a certain command which takes a long time finally is complete.
Locally, I know of several ways of how to get notified using a pop-up, playing something, … (1), (2) by running a certain command. Now I would need to do the same remotely. A perfect solution would be some sort of feedback channel right in ssh but I'm not aware of any such functionality.
And please no email-based solution as suggested in (3). I'm getting already too many work emails and I'm trying to dial down the amount of emails for something just to acknowledge but not for reading, storing, forwarding or replying to (for this I even created a separate email account for which I don't get real-time notifications).
https://superuser.com/questions/345447/how-can-i-trigger-a-notification-when-a-job-process-ends
https://askubuntu.com/questions/277215/make-a-sound-once-process-is-complete
Alert when running process finishes
|
The simplest solution is to use the exit from tmux, by issuing a tmux detach, to close the ssh connection, then send a notification, and then reconnect and attach back to the tmux. Eg with the script
ssh -t remote tmux
notify-send done
ssh -t remote tmux attach
You run tmux, and start off your long-running command, then type-ahead the command
tmux detach
which will run when the long command is done. This will close tmux, close the ssh, and the notify-send will show your desktop message. A new ssh will reattach exactly where you left off.
| Notification that remote process completed (but no email) |
1,638,661,752,000 |
A question arose in a group discussion: Can directory listing be disabled for sftp while still retaining read and write access?
We are using openssh on ubuntu server 11.02 if that helps.
|
Remove Read access.
Read access on a directory means that you can see a listing of files within that directory.
Execute (X) access means you can cd into the directory or traverse it
Write access means that you are able to add or change items within the directory.
| Can directory listing be disabled for sftp? |
1,638,661,752,000 |
$ ssh 192.168.29.126
The authenticity of host '192.168.29.126 (192.168.29.126)' can't be established.
ECDSA key fingerprint is SHA256:1RG/OFcYAVv57kcP784oaoeHcwjvHDAgtTFBckveoHE.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
What is the "fingerprint" it is asking for?
|
The question asks whether you trust and want to continue connecting to the host that SSH does not recognise. It gives you several ways of answering:
yes, you trust the host and want to continue connecting to it.
no, you do not trust the host, and you do not want to continue connecting to it.
[fingerprint] means that you may paste in the fingerprint, i.e. the hash of the host's key, as the reply to the question. If the pasted fingerprint is the same as the host's fingerprint (as discovered by SSH), then the connection continues; otherwise, it's terminated.
The fingerprint that answers the question in the affirmative is the exact string shown in the actual question (SHA256:1RG/OFcYAVv57kcP784oaoeHcwjvHDAgtTFBckveoHE in your case). If you have stored this fingerprint elsewhere, it's easier to paste it in from there than to compare the long string by eye.
In short: The third answer alternative provides a convenient way to verify that the fingerprint for the host is what you think it should be.
Using the fingerprint to answer the question was introduced in OpenSSH 8.0 (in 2019).
The commit message reads
Accept the host key fingerprint as a synonym for "yes" when accepting
an unknown host key. This allows you to paste a fingerprint obtained
out of band into the yes/no prompt and have the client do the comparison
for you. ok markus@ djm@
| What is the fingerprint ssh is asking for? |
1,638,661,752,000 |
There is already a great question and answer here, but I have a different case.
I create a tunnel with the following command:
$ ssh -N -R 0:192.168.0.16:80 [email protected]
Allocated port 35007 for remote forward to 192.168.0.16:80
I am getting output about the allocated port, however, when I background the tunnel with -f flag, I am having no output in stdout/strerr.
Is there a way to know the port in this case, without running some scripts on a remote server or using sockets like in the question I linked above?
Thanks!
|
Trying with the -f flag does indeed prevent the report that is given otherwise. Looking at the documentation (man ssh, search for -f), we can see that
-f Requests ssh to go to background just before command execution.
But in the next paragraph we can read,
If the ExitOnForwardFailure configuration option is set to yes, then a client started with -f will wait for all remote port forwards to be successfully established before placing itself in the background.
This implies that without this setting the command drops itself into the background immediately, and this is why it cannot report the allocated port to you.
This leads to a modified command, which does indeed report a message such as Allocated port 1234 for remote forward to 192.168.0.16:80:
ssh -o ExitOnForwardFailure=yes -fN -R 0:192.168.0.16:80 [email protected]
However, trying to capture that in a variable quickly identifies that it's being written to stderr rather than stdout. The final solution, therefore, is this:
port=$(
ssh -o ExitOnForwardFailure=yes -fN -R 0:192.168.0.16:80 [email protected] 2>&1 |
awk '/Allocated/{print $3+0}'
)
[ -n "$port" ] && echo "Port $port was allocated"
resulting in an output such as this:
Port 42655 was allocated
| Saving the dynamically allocated port of SSH tunnel |
1,638,661,752,000 |
I will send a string from a local machine to a remote ssh server.
The user is in a simple jail, so he can't execute commands, login, do something on the remote bash or what ever, he can only send a string/value/variable and execute the script run on the ssh server not more.
This is the simple jail for the user
This is are the default settings for the USER to login and run a shell:
chsh -s /bin/bash [USER]
But i change the settings to this for the simple jail:
chsh -s /home/[USER]/./run [USER]
The ssh server receive the string and change the string to a new result.
I save this new result on my local machine in a file called OUTPUT.
After trying i found this solution, call it a hack or a bug, but i don't know if this is the correct way!
With this command i ssh to the remote server, with a ssh-key without a password.
MY SSH COMMAND ON THE LOCAL MACHINE TO CONNECT TO THE SERVER:
ssh -i [KEY] -p [XXXX] [USER]@[HOST] '123' <<< "$VALUE" > OUTPUT
The script run receive the string 123 from the variable $VALUE
MY SCRIPT WITH NAME run ON THE SSH SERVER
#!/bin/bash
echo "WELCOME TO SSH"
read VALUE
echo $VALUE
This is only an example to See what i mean, the real Script generate a Hash.
On my local machine i store/save the result in my file OUTPUT from the script run of the remote ssh server.
MY LOCAL FILE OUTPUT WITH THE RESULT FROM THE SERVER
WELCOME TO SSH
123
The read VALUE command saves the value 123 in the variable $VALUE without a prompt and save the result on my local machine.
THE EXECUTION STEPS:
Connect to ssh server
Send a string from my local machine to the remote ssh server
The remote server change this string to a new result
Save the new result on my local machine in a file
When i start the ssh command it opens connection,
the script works, i see WELCOME TO SSH on my terminal and
i receive the result on my local machine and the connection close.
You can easy test this example on your machine to see what i mean.
This is exactly what i need but i wonder:
Why i need the read
Why i get not a prompt.
What is an other solution for this example.
How can i send a string to a script on a server over ssh with a jailed user and save the result from the server on my local machine in a file?
UPDATE FOR SOLUTION
From @ilkkachu answer i can run this commands and send:
String and Variable:
ssh -i [KEY] -p [XXXX] [USER]@[HOST] "123" "$VALUE" > OUTPUT
String:
ssh -i [KEY] -p [XXXX] [USER]@[HOST] "123"> OUTPUT
Variable:
ssh -i [KEY] -p [XXXX] [USER]@[HOST] "$VALUE" > OUTPUT
Nothing:
ssh -i [KEY] -p [XXXX] [USER]@[HOST] > OUTPUT
#!/bin/bash
value= # empty by default
if [ "$1" = -c ]; then
value="$2"
fi
if [ -z "$value" ]; then
echo "value is empty" >&2
exit 1
fi
# do something with the value
echo "$value" | rev
SSH authorized_keys command option
From this post:
SSH authorized_keys command option: multiple commands?
No. It is not "allowed" command, but "forced" command (as ForceCommand option).
The only possibility is to use different keys for different command or read parameters from stdin.
It is a good tip but for a single command, like a backup or output some informations.
I have to do more config stuff if i run a command like rsync, if i don't wanna receive errors.
So i will stay with a simple jailed user and a given script.
|
Using ssh user@somehost <<< "$value" is pretty much the same as echo "$value" | ssh user@somehost: the contents of the variable are sent to the standard input of the SSH client process. SSH transfers that to the remote end, and it's available there for the remote process to read, again on stdin. For example using the shell's read, as you did there. That's one way of passing data over the SSH connection.
Another way is using command line arguments. If you run
ssh user@somehost "some string here"
then SSH asks the remote side to run the remote user's shell with the two arguments -c and some string here. With a normal shell, that would have the shell interpret "some string here" as a shell command line, so indeed something like ssh user@somehost "ls /tmp" would work to run ls. (ssh user@somehost ls /tmp does the same, the SSH client joins the args with spaces before sending them to the remote.)
But you have changed the user's shell to limit what they can do, so the -c option will not do what SSH assumes it does. For the same reason, there's no prompt: your script doesn't print one like a normal shell would.
Having the script as the shell doesn't matter, though, as it can just detect and ignore the -c option and use what comes after it.
E.g. you could have a script like this on the remote:
#!/bin/bash
value= # empty by default
if [ "$1" = -c ]; then
value="$2"
fi
if [ -z "$value" ]; then
echo "value is empty" >&2
exit 1
fi
# do something with the value
echo "$value" | rev
The mock example would pass the value through rev, reversing the string.
Hence, running ssh user@somehost "hello there" would give back the string ereht olleh.
Running just ssh user@somehost, without a "command" at the end, would trigger the error message in the script, but it also would have SSH act like it was starting an interactive session. It would reserve pseudo-terminal (pty) on the remote, and might run some extra stuff usually done during login, like run PAM session modules on Linux. Those do stuff like printing the "Message of the day" or checking if the account had unread email. Same with ssh user@somehost "", so you can't really pass an empty argument and expect it to behave exactly the same as a non-empty one.
In addition to restricting the shell of the remote user, another alternative for locking the commands that can be run through SSH would be to use SSH keys, and to use the command=... in authorized_keys. Doing that would also allow disabling pty allocation with the no-pty keyword. (And the mere fact of running a forced command related to the key might affect running those PAM session modules.) See the sshd man page.
| How can i send a string to a script on a server over ssh with a simple jailed user and save the result from the server on my local machine in a file? |
1,638,661,752,000 |
Question
When I start SSH server, my Debian automatically start the SFTP server as well - why is it design in such way?
Environment:
Linux 5.10.0-14-amd64 Debian 5.10.113-1 (2022-04-29) x86_64 GNU/Linux
ssh.service - OpenBSD Secure Shell server
Background
Today I realized:
when I want to handle http requests, I start a web server - Apache(2), Node.js, etc.
when I want to handle SSH, I start an SSH server
when I want to handle SFTP... Debian already started SFTP server for me
So I researched, and according to this post 378313/default-sftp-server-in-debian-9-stretch, I found out SFTP is started as "part of (Open)SSH" which makes perfect sense but also feels strange for reasons such as separation of concerns.
Unlike Windows, I have never felt Debian doing something unexpected or extra on my behalf. But today I felt it - after all I said systemctl restart ssh, not systemctl restart ssh-and-also-ftp (the latter command is made-up).
As I am new to Unix/Linux and its philosophy, I would appreciate if there are any good explanations for this situation.
|
Although SFTP is not part of the extensible core SSH protocol, it is built-in to at least one of the the common SSH implementations (OpenSSH) and therefore can be considered to be a standard component.
You can disable the functionality on the server if it's not required by changing /etc/ssh/sshd_config so that you remove the Subsystem line corresponding to the sftp-server.
For example, this line defines an external sftp-server utility to handle the SFTP service:
Subsystem sftp-server
This line defines an internal implementation of the SFTP service:
Subsystem internal-sftp
Removing or commenting out the Subsystem line will disable the SFTP service entirely.
# Subsystem …
Remember that tools such as rsync (if it's installed) and versions of scp will still function, though, so disabling SFTP will not of itself prevent users from transferring files between client and server. (Older versions of scp will work independently of SFTP. Newer versions use SFTP but can be forced to use the older protocol with the -O flag.) There are also "trivial" solutions such as ssh remoteHost cat somefile > local_copy_of_somefile to consider.
| Why do I not need to start an SFTP Server ( why does SSH automatically start SFTP )? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.