LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-27-2018, 02:22 AM   #1
LeemaSingh
LQ Newbie
 
Registered: Jul 2018
Posts: 9

Rep: Reputation: Disabled
lua script


I want to do ssh to a remote machine and run tcpdump command in the background.Is it possible in the lua script and to provide password automatically.
 
Old 07-27-2018, 03:59 AM   #2
notKlaatu
Senior Member
 
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,077

Rep: Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732
You want the Lua script to provide the SSH password?

You could probably drum up something like that, but it would be easier to use the mechanisms that SSH already has: SSH keys.

Create a key on your local machine:

Code:
$ ssh-key-gen
Then copy that key to the remote computer:

Code:
$ ssh-copy-id user@remote-computer.com
Now you can login to the remote without a password.

Code:
$ ssh user@remote-computer.com
 
Old 07-27-2018, 04:20 AM   #3
LeemaSingh
LQ Newbie
 
Registered: Jul 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
lua script

but i want to do it using password method only without using any sshpass utility and sshkey mechanisms
 
Old 07-27-2018, 05:25 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Quote:
Originally Posted by LeemaSingh View Post
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.
 
Old 07-27-2018, 06:11 AM   #5
LeemaSingh
LQ Newbie
 
Registered: Jul 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
lua script

As the remote servers may not allow to do that.
 
Old 07-27-2018, 06:51 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by LeemaSingh View Post
As the remote servers may not allow to do that.
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
 
Old 07-27-2018, 07:12 AM   #7
LeemaSingh
LQ Newbie
 
Registered: Jul 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
lua script

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.
 
Old 07-29-2018, 01:09 PM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by LeemaSingh View Post
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.
 
1 members found this post helpful.
Old 07-30-2018, 04:35 AM   #9
LeemaSingh
LQ Newbie
 
Registered: Jul 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
lua script

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.
 
Old 07-30-2018, 04:41 AM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Quote:
Originally Posted by LeemaSingh View Post
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.
 
1 members found this post helpful.
Old 07-30-2018, 05:03 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
@OP Kindly explain why would you want to run tcpdump on someone else's computer.
 
1 members found this post helpful.
Old 07-30-2018, 06:50 AM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by LeemaSingh View Post
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.
 
Old 07-30-2018, 06:56 AM   #13
LeemaSingh
LQ Newbie
 
Registered: Jul 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
lua script

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 &"')
 
Old 07-30-2018, 07:03 AM   #14
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Quote:
Originally Posted by LeemaSingh View Post
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.
 
1 members found this post helpful.
Old 07-30-2018, 07:17 AM   #15
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by LeemaSingh View Post
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 &"')
Because you are ignoring the advice you were given about the correct way to do this.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
lua script LeemaSingh Linux - Newbie 2 07-27-2018 07:13 AM
[SOLVED] conky install: where to run LUA=yes script? textillis Slackware 9 07-26-2013 11:09 PM
[SOLVED] Conky with lua. flyinggeorge Linux - Software 6 06-19-2013 03:00 PM
lua how to get process id? fantasy1215 Programming 1 05-11-2012 04:12 AM
Conky + lua flyinggeorge Linux - Software 6 03-05-2012 08:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration