ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
but i want to do it using password method only without using any sshpass utility and sshkey mechanisms
It's doable but can you first say why? Keys are very easy. Using SSH keys is considered a well-established best practice and password authentication is something to avoid for the most part.
Ok...so since you'd like a script, can you show us what you have done/tried/written so far?? Read the "Question Guidelines" link in my posting signature. We are happy to help you, but we will NOT write scripts for you. You have to show your own efforts
This is what i have tried so far,but its wrong i should'nt have used sshpass and there is problem that i can't see tcpdump process running in remote machine :
function tcpdump_file(pwd,user,ip,filename,cmd)
os.execute('sshpass -p '..pwd..' ssh '..user..'@'..ip..'<<exit')
if cmd=='start' then
os.execute('tcpdump -i 2 -w '..filename..' &')
elseif cmd=='stop' then
os.execute("kill -9 `ps -ef | grep "..filename.." | grep -v grep | awk '{print $2}'`")
end
os.execute('exit')
end
tcpdump_file("lee123","guest","192.168.14.68","test123.pcap",'start')
Last edited by LeemaSingh; 07-27-2018 at 07:32 AM.
This is what i have tried so far,but its wrong i should'nt have used sshpass and there is problem that i can't see tcpdump process running in remote machine :
Code:
function tcpdump_file(pwd,user,ip,filename,cmd)
os.execute('sshpass -p '..pwd..' ssh '..user..'@'..ip..'<<exit')
if cmd=='start' then
os.execute('tcpdump -i 2 -w '..filename..' &')
elseif cmd=='stop' then
os.execute("kill -9 `ps -ef | grep "..filename.." | grep -v grep | awk '{print $2}'`")
end
os.execute('exit')
end
tcpdump_file("lee123","guest","192.168.14.68","test123.pcap",'start')
Use CODE tags when posting code. And since you acknowledge you shouldn't have used sshpass, is there a reason you can just do an SSH keyswap, and do it without a password?? You say:
Quote:
As the remote servers may not allow to do that.
...but do you *KNOW* they won't?? If you have an SSH login, you almost certainly can do this. Further, if you're the administrator, and you're doing something authorized, you should easily be able to get any access you need to accomplish your task.
Yes i know that i have used sshpass its just part for trial and error method because i don't know the method to provide the password automatically.Can you give some hint.
The hint is to use SSH keys. There are thousands of guides and tutorials. You'll want to ignore any leftovers recommending DSA keys. Use Ed25519 keys with SSH to look forward or fall back to RSA if backward compatibility with specific dongles is needed.
The programs to look at are ssh-keygen and ssh-copy-id. For the former, be sure to remember the -f and -C options. See "man ssh-keygen" and "man ssh_copy-id" The file to look at on the destination machine is ~/.ssh/authorized_keys
As for more of a hint, that was given back there in post #2 with specifics.
Yes i know that i have used sshpass its just part for trial and error method because i don't know the method to provide the password automatically.Can you give some hint.
You were given 'hints'...they are to do an SSH keyswap. There are *THOUSANDS* of easily found guides that tell you how to do this, including the ssh-copy-id command, which you could find with a brief search. This has also been covered many, MANY times on this site as well.
why this command is terminating the process s.execute('sshpass -p lee123 ssh user@192.168.14.81 "nohup sudo tcpdump -i wlan0 -w t5.pcap &"')
The ssh client quits after it has launched the remote process under nohup into the background using the ampersand & there. The file t5.pcap should continue to grow. Log into the remote machine and verify that t5.pcap is there and growing. You should use a full path for that file though so you can put it somewhere useful.
Again I will nag you to set up SSH keys, that will allow you to eliminate several unnecessary steps. If you have root (sudo) then there is no reason not to be able to use keys.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.