Ssh ошибка 255

In my code I have the following to run a remote script.

ssh root@host.domain.com "sh /home/user/backup_mysql.sh"

For some reason it keeps 255’ing on me. Any ideas?

I can SSH into the box just fine (passless keys setup)

REMOTE SCRIPT:

MUSER='root' 
MPASS='123123'
MHOST="127.0.0.1"
VERBOSE=0

### Set bins path ###
GZIP=/bin/gzip
MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump
RM=/bin/rm
MKDIR=/bin/mkdir
MYSQLADMIN=/usr/bin/mysqladmin
GREP=/bin/grep

### Setup dump directory ###
BAKRSNROOT=/.snapshots/tmp

#####################################
### ----[ No Editing below ]------###
#####################################
### Default time format ###
TIME_FORMAT='%H_%M_%S%P'

### Make a backup ###
backup_mysql_rsnapshot(){
        local DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
        local db="";
        [ ! -d $BAKRSNROOT ] && ${MKDIR} -p $BAKRSNROOT
        ${RM} -f $BAKRSNROOT/* >/dev/null 2>&1
#       [ $VERBOSE -eq 1 ] && echo "*** Dumping MySQL Database ***"
#       [ $VERBOSE -eq 1 ] && echo -n "Database> "
        for db in $DBS
        do
                local tTime=$(date +"${TIME_FORMAT}")
                local FILE="${BAKRSNROOT}/${db}.${tTime}.gz"
#               [ $VERBOSE -eq 1 ] && echo -n "$db.."
                ${MYSQLDUMP} --single-transaction -u ${MUSER} -h ${MHOST} -p${MPASS} $db | ${GZIP} -9 > $FILE
        done
#               [ $VERBOSE -eq 1 ] && echo ""
#               [ $VERBOSE -eq 1 ] && echo "*** Backup done [ files wrote to $BAKRSNROOT] ***"
}

### Die on demand with message ###
die(){
        echo "$@"
        exit 999
}

### Make sure bins exists.. else die
verify_bins(){
        [ ! -x $GZIP ] && die "File $GZIP does not exists. Make sure correct path is set in $0."
        [ ! -x $MYSQL ] && die "File $MYSQL does not exists. Make sure correct path is set in $0."
        [ ! -x $MYSQLDUMP ] && die "File $MYSQLDUMP does not exists. Make sure correct path is set in $0."
        [ ! -x $RM ] && die "File $RM does not exists. Make sure correct path is set in $0."
        [ ! -x $MKDIR ] && die "File $MKDIR does not exists. Make sure correct path is set in $0."
        [ ! -x $MYSQLADMIN ] && die "File $MYSQLADMIN does not exists. Make sure correct path is set in $0."
        [ ! -x $GREP ] && die "File $GREP does not exists. Make sure correct path is set in $0."
}

### Make sure we can connect to server ... else die
verify_mysql_connection(){
        $MYSQLADMIN  -u $MUSER -h $MHOST -p$MPASS ping | $GREP 'alive'>/dev/null
        [ $? -eq 0 ] || die "Error: Cannot connect to MySQL Server. Make sure username and password are set correctly in $0"
}

### main ####
verify_bins
verify_mysql_connection
backup_mysql_rsnapshot

5

This is usually happens when the remote is down/unavailable; or the remote machine doesn’t have ssh installed; or a firewall doesn’t allow a connection to be established to the remote host.

ssh returns 255 when an error occurred or 255 is returned by the remote script:

 EXIT STATUS

     ssh exits with the exit status of the remote command or
     with 255 if an error occurred.

Usually you would an error message something similar to:

ssh: connect to host host.domain.com port 22: No route to host

Or

ssh: connect to host HOSTNAME port 22: Connection refused

Check-list:

  • What happens if you run the ssh command directly from the command line?

  • Are you able to ping that machine?

  • Does the remote has ssh installed?

  • If installed, then is the ssh service running?

answered Feb 14, 2013 at 23:30

P.P's user avatar

6

This error will also occur when using pdsh to hosts which are not contained in your «known_hosts» file.

I was able to correct this by SSH’ing into each host manually and accepting the question «Do you want to add this to known hosts».

1

If there’s a problem with authentication or connection, such as not being able to read a password from the terminal, ssh will exit with 255 without being able to run your actual script. Verify to make sure you can run ‘true’ instead, to see if the ssh connection is established successfully.

answered Feb 14, 2013 at 23:28

that other guy's user avatar

that other guythat other guy

116k11 gold badges168 silver badges193 bronze badges

Isn’t the problem in the lines:

### Die on demand with message ###
die(){
  echo "$@"
  exit 999
}

Correct me if I’m wrong but I believe exit 999 is out of range for an exit code and results in a exit status of 255.

1

I was stumped by this. Once I got passed the 255 problem… I ended up with a mysterious error code 1. This is the foo to get that resolved:

 pssh -x '-tt' -h HOSTFILELIST -P "sudo yum -y install glibc"

-P means write the output out as you go and is optional. But the -x ‘-tt’ trick is what forces a psuedo tty to be allocated.

You can get a clue what the error code 1 means this if you try:

ssh AHOST "sudo yum -y install glibc"

You may see:

[slc@bastion-ci ~]$ ssh MYHOST "sudo yum -y install glibc"
sudo: sorry, you must have a tty to run sudo
[slc@bastion-ci ~]$ echo $?
1

Notice the return code for this is 1, which is what pssh is reporting to you.

I found this -x -tt trick here. Also note that turning on verbose mode (pssh —verbose) for these cases does nothing to help you.

It can very much be an ssh-agent issue.
Check whether there is an ssh-agent PID currently running with eval "$(ssh-agent -s)"

Check whether your identity is added with ssh-add -l and if not, add it with ssh-add <pathToYourRSAKey>.

Then try again your ssh command (or any other command that spawns ssh daemons, like autossh for example) that returned 255.

### Die on demand with message ###
die(){
        echo "$@"
        exit 999
}

I don’t have the rep to comment on Alex’s answer but the exit 999 line returns code 231 on my WSL Ubuntu 20.04.4 box. Not quite sure why that is returned but I understand that it’s out of range.

1

The SSH (Secure Shell) script is a powerful tool for accessing remote servers and performing various operations on them. However, sometimes when you run an SSH script, it returns an error code of 255. This error code indicates that the remote server has rejected the connection and the script execution has failed. There are several reasons why the remote server may reject the connection, including incorrect authentication information, firewall restrictions, or an unstable network connection.

Method 1: Check the Authentication Information

To fix the «ssh script returns 255 error» in Linux, you can check the authentication information. Here are the steps to do so:

  1. Check the user’s permissions and ensure that they have the necessary access to the remote server.
ls -la ~/.ssh/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
  1. Verify that the authentication keys are correctly installed and that the permissions are set correctly.
cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> ~/.ssh/authorized_keys'
  1. Ensure that the SSH server is running and that the firewall is not blocking the connection.
systemctl status sshd
firewall-cmd --list-all
  1. Check the SSH logs for any errors or issues.
  1. Try connecting to the remote server manually and see if there are any errors.

By following these steps, you should be able to fix the «ssh script returns 255 error» in Linux.

Method 2: Check Firewall Restrictions

If you are encountering a «ssh script returns 255 error» in Linux, it may be due to firewall restrictions. Here’s how to fix it:

Step 1: Check Firewall Restrictions

First, check if there are any firewall restrictions that may be causing the error. You can do this by running the following command:

This will show you the current status of your firewall. If it is active, you may need to allow SSH connections through the firewall. You can do this by running the following command:

Step 2: Test SSH Connection

Next, test your SSH connection to see if the error has been resolved. You can do this by running the following command:

Replace «user» with your username and «server» with the name or IP address of the server you are trying to connect to.

If you are still encountering the «ssh script returns 255 error», you may need to check your SSH configuration or consult with your system administrator.

Method 3: Stabilize the Network Connection

To stabilize the network connection and fix the ssh script returns 255 error on Linux, follow these steps:

  1. Set up a keepalive interval on the client side by editing the ssh_config file:
sudo nano /etc/ssh/ssh_config

Add the following line at the end of the file:

This will send a keepalive packet every 60 seconds to keep the connection alive.

  1. Set up a keepalive interval on the server side by editing the sshd_config file:
sudo nano /etc/ssh/sshd_config

Add the following line at the end of the file:

This will send a keepalive packet every 60 seconds to keep the connection alive.

  1. Restart the ssh service on both the client and server side:
  1. Test the connection by running the ssh script again.

Here’s an example of what the edited ssh_config and sshd_config files would look like:

/etc/ssh/ssh_config

/etc/ssh/sshd_config

With these changes, the ssh connection should be more stable and the script should no longer return a 255 error.

Method 4: Debug the Script for Errors

When dealing with SSH scripts returning a 255 error, debugging the script for errors is a good approach. Here are the steps to do it:

  1. Check the syntax of the script. Run bash -n scriptname.sh to check for syntax errors.

  2. Add set -x at the beginning of the script to enable debugging mode. This will print each command as it is executed.

  3. Run the script again and check for errors in the output. Look for any command that might be failing.

  4. Use echo statements to print out variables and values to help identify where the error might be occurring.

Here is an example script with debugging enabled:

#!/bin/bash
set -x

ssh user@remote-server "echo Hello World"

In this example, the set -x command will print out each command as it is executed. If there is an error with the SSH connection, it will be apparent in the output.

Debugging scripts for errors can be time-consuming, but it is an effective way to identify and fix issues. By following these steps and using the set -x command, you can quickly identify the source of the error and resolve it.

Are you struggling with sftp error code 255?

SFTP is a secure method for file upload.

However, it often shows errors when the remote server is down/unavailable, the remote machine doesn’t have ssh access or has firewall restrictions.

At Bobcares, we often get requests from our customers to fix an error message sftp error code 255 as part of our Server Management Services.

Today, let’s get into the details on how our Support Engineers fix this error.

Why sftp error code 255?

Usually, the exit code 255 is a frequent error that happens due to the problem in SSH access.

The error appears like the following

SFTP error 255

The following reasons are the common cause of this error.

If the remote server to which we are trying to connect is unavailable or down, then the connection via sftp has not been established, and so we received this error.

In addition to this, we will get the same error if the remote server is not having the ssh access to the server or if there is any firewall restriction.

Now let’s detail the reason for this error and how our Support Engineers fix the problem.

The causes and fixes of sftp error code 255

At Bobcares, where we have more than a decade of expertise in managing servers, we see many customers facing problems with error sftp error code 255.

Now, let’s see the major reasons for this sftp related errors and how our Support Engineers fix them.

1. Missing RSA key

Recently, while connecting to the server via sftp one of our customers was getting the error sftp error code 255. Initially, his public key authentication was successful. But after a while, the connection got disconnected.

On checking, our Support Engineers found that the public key was working and could not trace anything wrong with it. However, we found that he had only created DSA keys, and RSA keys were missing.

Therefore, we created RSA keys and also inserted the public keys in his authorized keys file, then everything worked fine.

This resolved the error and the customer could regain sftp connection.

2. Firewall restrictions

Firewall restrictions can also be a reason for sftp failure. It will restrict unauthorized IP access or port access to the server for security purposes.

Sometimes, the error sftp error code 255 happens due to the sftp port restricted in the firewall. In such cases, our Support Engineers will first check for any firewall restrictions. Firewall restrictions can cause timeout errors while trying to connect to the server using sftp.

This has been caused due to some server-side settings or sftp port (default 22)blocks on the network.

So, our Support Engineers check the log files and confirm that it does not cause the sftp to exit connection.

For instance, we check the IPtables to see if there are any IP restrictions.

iptables -nL | grep xx.xx.xx.xx

If so, we will remove the IP restrictions to fix this error.

3. Permission of sftp

Sometimes, if there was no sftp server on the remote end, customers will receive the same error. Here, our Support Engineers confirm the working of the sftp server.

Another important cause to receive this error is incorrect permission of /home/user and .ssh folder on the remote server.

Here, we check the permission of the user and .ssh folder and correct it as follows.

chmod 755 /home/user
chmod 700 /home/user/.ssh

Generally, the /home/user folder should be with 755 permission and the .ssh folder is with 700 permission.

By ensuring this, we can avoid unwanted errors happens while connected to the remote server via sftp.

[Struggling with sftp connection errors? We are here to help you.]

Conclusion

In short, sftp error code 255 error has been received mainly due to the problems in the remote server such as missing RSA keys, firewall restrictions, and so on. Today we discussed the reasons causing sftp error code 255 and saw how our Support Engineers fix this error for our customers.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

Hi folks,

Here’s what I’m trying to do. I’ve a number of Ubuntu servers (version 18 and 20), and I’m wanting to run the same script against several of them.

It’s my understanding that parallel-ssh will do the trick for me.

Here’s what I’ve done.

First things I did was install parallel-ssh using sudo apt-get install pssh

next I create to files. The first I created using sudo nano ~/pssh-commands

I copied and pasted the following in and saved it:

#!/bin/bash

echo

 # show system uptime 

uptime 

echo 

exit 0

I saved that, and then created another using nano ~/pssh-hosts

This is text file that consists of several IP addresses set up as:

usernameIP_Address​ with the username being our admin account and ip address being the Ubuntu servers.

I saved that.

then I an it using 

parallel-ssh -h pssh-hosts -A -P -I < pssh-command

And this is what I get:

Image: post content

Any Ideas why I might be getting that.

Solution 1

This is usually happens when the remote is down/unavailable; or the remote machine doesn’t have ssh installed; or a firewall doesn’t allow a connection to be established to the remote host.

ssh returns 255 when an error occurred or 255 is returned by the remote script:

 EXIT STATUS

     ssh exits with the exit status of the remote command or
     with 255 if an error occurred.

Usually you would an error message something similar to:

ssh: connect to host host.domain.com port 22: No route to host

Or

ssh: connect to host HOSTNAME port 22: Connection refused

Check-list:

  • What happens if you run the ssh command directly from the command line?

  • Are you able to ping that machine?

  • Does the remote has ssh installed?

  • If installed, then is the ssh service running?

Solution 2

This error will also occur when using pdsh to hosts which are not contained in your «known_hosts» file.

I was able to correct this by SSH’ing into each host manually and accepting the question «Do you want to add this to known hosts».

Solution 3

If there’s a problem with authentication or connection, such as not being able to read a password from the terminal, ssh will exit with 255 without being able to run your actual script. Verify to make sure you can run ‘true’ instead, to see if the ssh connection is established successfully.

Solution 4

I was stumped by this. Once I got passed the 255 problem… I ended up with a mysterious error code 1. This is the foo to get that resolved:

 pssh -x '-tt' -h HOSTFILELIST -P "sudo yum -y install glibc"

-P means write the output out as you go and is optional. But the -x ‘-tt’ trick is what forces a psuedo tty to be allocated.

You can get a clue what the error code 1 means this if you try:

ssh AHOST "sudo yum -y install glibc"

You may see:

[[email protected] ~]$ ssh MYHOST "sudo yum -y install glibc"
sudo: sorry, you must have a tty to run sudo
[[email protected] ~]$ echo $?
1

Notice the return code for this is 1, which is what pssh is reporting to you.

I found this -x -tt trick here. Also note that turning on verbose mode (pssh —verbose) for these cases does nothing to help you.

Solution 5

It can very much be an ssh-agent issue.
Check whether there is an ssh-agent PID currently running with eval "$(ssh-agent -s)"

Check whether your identity is added with ssh-add -l and if not, add it with ssh-add <pathToYourRSAKey>.

Then try again your ssh command (or any other command that spawns ssh daemons, like autossh for example) that returned 255.

Comments

  • In my code I have the following to run a remote script.

    ssh [email protected] "sh /home/user/backup_mysql.sh"
    

    For some reason it keeps 255’ing on me. Any ideas?

    I can SSH into the box just fine (passless keys setup)

    REMOTE SCRIPT:

    MUSER='root' 
    MPASS='123123'
    MHOST="127.0.0.1"
    VERBOSE=0
    
    ### Set bins path ###
    GZIP=/bin/gzip
    MYSQL=/usr/bin/mysql
    MYSQLDUMP=/usr/bin/mysqldump
    RM=/bin/rm
    MKDIR=/bin/mkdir
    MYSQLADMIN=/usr/bin/mysqladmin
    GREP=/bin/grep
    
    ### Setup dump directory ###
    BAKRSNROOT=/.snapshots/tmp
    
    #####################################
    ### ----[ No Editing below ]------###
    #####################################
    ### Default time format ###
    TIME_FORMAT='%H_%M_%S%P'
    
    ### Make a backup ###
    backup_mysql_rsnapshot(){
            local DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
            local db="";
            [ ! -d $BAKRSNROOT ] && ${MKDIR} -p $BAKRSNROOT
            ${RM} -f $BAKRSNROOT/* >/dev/null 2>&1
    #       [ $VERBOSE -eq 1 ] && echo "*** Dumping MySQL Database ***"
    #       [ $VERBOSE -eq 1 ] && echo -n "Database> "
            for db in $DBS
            do
                    local tTime=$(date +"${TIME_FORMAT}")
                    local FILE="${BAKRSNROOT}/${db}.${tTime}.gz"
    #               [ $VERBOSE -eq 1 ] && echo -n "$db.."
                    ${MYSQLDUMP} --single-transaction -u ${MUSER} -h ${MHOST} -p${MPASS} $db | ${GZIP} -9 > $FILE
            done
    #               [ $VERBOSE -eq 1 ] && echo ""
    #               [ $VERBOSE -eq 1 ] && echo "*** Backup done [ files wrote to $BAKRSNROOT] ***"
    }
    
    ### Die on demand with message ###
    die(){
            echo "$@"
            exit 999
    }
    
    ### Make sure bins exists.. else die
    verify_bins(){
            [ ! -x $GZIP ] && die "File $GZIP does not exists. Make sure correct path is set in $0."
            [ ! -x $MYSQL ] && die "File $MYSQL does not exists. Make sure correct path is set in $0."
            [ ! -x $MYSQLDUMP ] && die "File $MYSQLDUMP does not exists. Make sure correct path is set in $0."
            [ ! -x $RM ] && die "File $RM does not exists. Make sure correct path is set in $0."
            [ ! -x $MKDIR ] && die "File $MKDIR does not exists. Make sure correct path is set in $0."
            [ ! -x $MYSQLADMIN ] && die "File $MYSQLADMIN does not exists. Make sure correct path is set in $0."
            [ ! -x $GREP ] && die "File $GREP does not exists. Make sure correct path is set in $0."
    }
    
    ### Make sure we can connect to server ... else die
    verify_mysql_connection(){
            $MYSQLADMIN  -u $MUSER -h $MHOST -p$MPASS ping | $GREP 'alive'>/dev/null
            [ $? -eq 0 ] || die "Error: Cannot connect to MySQL Server. Make sure username and password are set correctly in $0"
    }
    
    ### main ####
    verify_bins
    verify_mysql_connection
    backup_mysql_rsnapshot
    

Recents

Related

Понравилась статья? Поделить с друзьями:
  • Ssh ошибка 1005
  • S0392 ошибка bmw
  • Sseoverlay dll ошибка
  • S0379 ошибка бмв
  • Sse3 ошибка яндекс