Hi, I was going through the code of open ssh server part ( code for sshd ). My query is when user gives any command ( for example unix command "ls") in the console ( after ssh login is complete ), which function in sshd will execute this command. I traced that the command is coming to sshd code in message type SSH2_MSG_CHANNEL_DATA. There is a check using function packet_check_eom(). But I am not able to trace the place where linux command "ls" will be executed. I want to know the function in sshd code which will execute this function. Hoping for your expertise in this regard. Kindly help. Best regards, Titu
--On 2 October 2011 05:22:23 -0700 titu senapati <titu_senapati at yahoo.com> wrote:> I was going through the code of open ssh server part ( code for sshd ). > My query is when user gives any command ( for example unix command "ls") > in the console ( after ssh login is complete ), which function in sshd > will execute this command.Assuming by "ssh login" you mean login in the sense of an interactive shell, ssh runs bash (or whatever shell the user has set up). It then passes stdin to bash over the ssh channel and prints stdout. Thus ssh isn't executing the commands, it's just passing them to an existing shell through an fd. -- Alex Bligh
On 10/02/2011 08:22 AM, titu senapati wrote:> I was going through the code of open ssh server part ( code for sshd ). My query is when user gives any command ( for example unix command "ls") > in the console ( after ssh login is complete ), which function in sshd will execute this command. I traced that the command is coming to sshd code > in message type SSH2_MSG_CHANNEL_DATA. There is a check using function packet_check_eom(). But I am not able to trace the place > where linux command "ls" will be executed. I want to know the function in sshd code which will execute this function.In the common case, sshd invokes a child process of the user's shell upon session creation. Then when the user types a command like "ls", that command gets shuttled across ssh as channel data (as you've seen) and handed as input to the child process (the shell). It is the shell which interprets the "ls" as a command and in turn invokes /bin/ls (or whatever). So sshd doesn't invoke ls directly at all. Make sense? hope this helps, --dkg -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 1030 bytes Desc: OpenPGP digital signature URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20111002/9ff6557a/attachment.bin>
On Sun, 2 Oct 2011, titu senapati wrote:> Hi, > > I was going through the code of open ssh server part ( code for sshd > ). My query is when user gives any command ( for example unix command > "ls") in the console ( after ssh login is complete ), which function > in sshd will execute this command. I traced that the command is coming > to sshd code in message type SSH2_MSG_CHANNEL_DATA. There is a check > using function packet_check_eom(). But I am not able to trace the > place where linux command "ls" will be executed. I want to know the > function in sshd code which will execute this function.What are you trying to do? (this looks a lot like a homework question) The request is not SSH2_MSG_CHANNEL_DATA but SSH2_MSG_CHANNEL_REQUEST. -d
Hi, My query is answered now.? Thanks to Alex, Daniel and Damien for the response. I searched the openssh code where SHELL process is started and got to know the steps. Thanks to all. Best Regards, Titu ________________________________ From: titu senapati <titu_senapati at yahoo.com> To: "openssh-unix-dev at mindrot.org" <openssh-unix-dev at mindrot.org> Sent: Sunday, October 2, 2011 5:52 PM Subject: Information on command execution in sshd Hi, I was going through the code of open ssh server part ( code for sshd ). My query is when user gives any command ( for example unix command "ls") in the console ( after ssh login is complete ), which function in sshd will execute this command. I traced that the command is coming to sshd code in message type SSH2_MSG_CHANNEL_DATA. There is a check using function packet_check_eom(). But I am not able to trace the place where linux command "ls" will be executed. I want to know the function in sshd code which will execute this function. Hoping for your expertise in this regard. Kindly help. Best regards, Titu