Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSH and SCP with a username specified #15

Open
ldmtwo opened this issue Dec 14, 2017 · 1 comment
Open

SSH and SCP with a username specified #15

ldmtwo opened this issue Dec 14, 2017 · 1 comment

Comments

@ldmtwo
Copy link

ldmtwo commented Dec 14, 2017

Could you add a feature and configuration that would allow specifying the user name? That way with SSH_KEY and the proposed USER config, the tool will be able to specify the rest of this.

From this_user@localhost:
ssh -i ~/.ssh/id_rsa THAT_user@remotehost

@ldmtwo
Copy link
Author

ldmtwo commented Dec 14, 2017

Below is the minimal solution to the above request. I added the USR variable and an echo of the actual command. Previously I was getting authentication errors because the user name was different.

This is the bottom of the common.sh file.


USR="hadoop@"
ssh_w() {
        h=$(echo $1 | cut -d: -f1) # hostname
        p=$(echo $1 | cut -d: -f2 -s) # port
        shift
        if test -z $p; then p=22; fi
        echo ssh $_ssh_key -p $p $USR$h "$@"
        ssh $_ssh_key -p $p $USR$h "$@"
}

scp_to_w() {
        # do not use as first parameter dir/*, use this between quotes
        # i.e "dir/*" (prevents shell expansion)
        h=$(echo $1 | cut -d: -f1) # hostname
        p=$(echo $1 | cut -d: -f2 -s) # port
        shift
        if test -z $p; then p=22; fi
        echo scp $_ssh_key -p -r -P $p $1 $USR$h:$2
        scp $_ssh_key -p -r -P $p $1 $USR$h:$2
}

scp_from_w() {
        # do not use as first parameter dir/*, use this between quotes
        # i.e "dir/*" (prevents shell expansion)
        h=$(echo $1 | cut -d: -f1) # hostname
        p=$(echo $1 | cut -d: -f2 -s) # port
        shift
        if test -z $p; then p=22; fi
        echo scp $_ssh_key -p -r -P $p $USR$h:$1 $2
        scp $_ssh_key -p -r -P $p $USR$h:$1 $2

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant