paramiko.ssh_exception.SSHException: Channel closed. Trying to connect to a remote machine with key-based...












0















Python noob here! I am trying to connect to a remote machine with paramiko (Python 3.7.1) with key-based authentication. Once connected I want to execute the command "ls -l" and print its output. But when I try to run the code below I get the error "paramiko.ssh_exception.SSHException: Channel closed".



import paramiko
from paramiko.transport import Transport

destination = '192.168.1.201'
port = 22
user = 'myUser'

privkey = paramiko.RSAKey.from_private_key_file ('/home/test/.ssh/test-private-key')
command = 'ls -l'
paramiko.Transport._preferred_kex = ('diffie-hellman-group14-sha1',)

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(destination,port,user,pkey=privkey)

(stdin, stdout, stderr) = ssh.exec_command(command)

print(stdout.read())
print(stderr.read())

stdin.close()
ssh.close


I have tested the SSH key-based authentication against the remote machine by using the command "myUser@192.168.1.201" which worked as intended. I also made sure that the current user (the user called test, which will run this script) has read permissions for the private key.



I can succesfully connect and run the command "ls -l" when I am not using key-based authentication with paramiko. This means I probably did something wrong when trying to get key-based authentication to work. But I just cannot figure out what I am doing wrong, I have looked up countless examples about paramiko and key-based authentication.










share|improve this question























  • Where do you get the error? Show us a full stacktrace. + Show us Paramiko log file. + Show us a verbose output (ssh -vvv switch) for your "SSH key-based authentication" test.

    – Martin Prikryl
    Nov 14 '18 at 7:07


















0















Python noob here! I am trying to connect to a remote machine with paramiko (Python 3.7.1) with key-based authentication. Once connected I want to execute the command "ls -l" and print its output. But when I try to run the code below I get the error "paramiko.ssh_exception.SSHException: Channel closed".



import paramiko
from paramiko.transport import Transport

destination = '192.168.1.201'
port = 22
user = 'myUser'

privkey = paramiko.RSAKey.from_private_key_file ('/home/test/.ssh/test-private-key')
command = 'ls -l'
paramiko.Transport._preferred_kex = ('diffie-hellman-group14-sha1',)

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(destination,port,user,pkey=privkey)

(stdin, stdout, stderr) = ssh.exec_command(command)

print(stdout.read())
print(stderr.read())

stdin.close()
ssh.close


I have tested the SSH key-based authentication against the remote machine by using the command "myUser@192.168.1.201" which worked as intended. I also made sure that the current user (the user called test, which will run this script) has read permissions for the private key.



I can succesfully connect and run the command "ls -l" when I am not using key-based authentication with paramiko. This means I probably did something wrong when trying to get key-based authentication to work. But I just cannot figure out what I am doing wrong, I have looked up countless examples about paramiko and key-based authentication.










share|improve this question























  • Where do you get the error? Show us a full stacktrace. + Show us Paramiko log file. + Show us a verbose output (ssh -vvv switch) for your "SSH key-based authentication" test.

    – Martin Prikryl
    Nov 14 '18 at 7:07
















0












0








0


1






Python noob here! I am trying to connect to a remote machine with paramiko (Python 3.7.1) with key-based authentication. Once connected I want to execute the command "ls -l" and print its output. But when I try to run the code below I get the error "paramiko.ssh_exception.SSHException: Channel closed".



import paramiko
from paramiko.transport import Transport

destination = '192.168.1.201'
port = 22
user = 'myUser'

privkey = paramiko.RSAKey.from_private_key_file ('/home/test/.ssh/test-private-key')
command = 'ls -l'
paramiko.Transport._preferred_kex = ('diffie-hellman-group14-sha1',)

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(destination,port,user,pkey=privkey)

(stdin, stdout, stderr) = ssh.exec_command(command)

print(stdout.read())
print(stderr.read())

stdin.close()
ssh.close


I have tested the SSH key-based authentication against the remote machine by using the command "myUser@192.168.1.201" which worked as intended. I also made sure that the current user (the user called test, which will run this script) has read permissions for the private key.



I can succesfully connect and run the command "ls -l" when I am not using key-based authentication with paramiko. This means I probably did something wrong when trying to get key-based authentication to work. But I just cannot figure out what I am doing wrong, I have looked up countless examples about paramiko and key-based authentication.










share|improve this question














Python noob here! I am trying to connect to a remote machine with paramiko (Python 3.7.1) with key-based authentication. Once connected I want to execute the command "ls -l" and print its output. But when I try to run the code below I get the error "paramiko.ssh_exception.SSHException: Channel closed".



import paramiko
from paramiko.transport import Transport

destination = '192.168.1.201'
port = 22
user = 'myUser'

privkey = paramiko.RSAKey.from_private_key_file ('/home/test/.ssh/test-private-key')
command = 'ls -l'
paramiko.Transport._preferred_kex = ('diffie-hellman-group14-sha1',)

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(destination,port,user,pkey=privkey)

(stdin, stdout, stderr) = ssh.exec_command(command)

print(stdout.read())
print(stderr.read())

stdin.close()
ssh.close


I have tested the SSH key-based authentication against the remote machine by using the command "myUser@192.168.1.201" which worked as intended. I also made sure that the current user (the user called test, which will run this script) has read permissions for the private key.



I can succesfully connect and run the command "ls -l" when I am not using key-based authentication with paramiko. This means I probably did something wrong when trying to get key-based authentication to work. But I just cannot figure out what I am doing wrong, I have looked up countless examples about paramiko and key-based authentication.







python-3.x paramiko






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 15:24









MilkBottleMilkBottle

41




41













  • Where do you get the error? Show us a full stacktrace. + Show us Paramiko log file. + Show us a verbose output (ssh -vvv switch) for your "SSH key-based authentication" test.

    – Martin Prikryl
    Nov 14 '18 at 7:07





















  • Where do you get the error? Show us a full stacktrace. + Show us Paramiko log file. + Show us a verbose output (ssh -vvv switch) for your "SSH key-based authentication" test.

    – Martin Prikryl
    Nov 14 '18 at 7:07



















Where do you get the error? Show us a full stacktrace. + Show us Paramiko log file. + Show us a verbose output (ssh -vvv switch) for your "SSH key-based authentication" test.

– Martin Prikryl
Nov 14 '18 at 7:07







Where do you get the error? Show us a full stacktrace. + Show us Paramiko log file. + Show us a verbose output (ssh -vvv switch) for your "SSH key-based authentication" test.

– Martin Prikryl
Nov 14 '18 at 7:07














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284226%2fparamiko-ssh-exception-sshexception-channel-closed-trying-to-connect-to-a-remo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284226%2fparamiko-ssh-exception-sshexception-channel-closed-trying-to-connect-to-a-remo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine