how to log all coming messages of SSH Secure Shell client? - security

I am using SSH Secure Shell client, a nice tool to connect to the server.
However, I am wondering whether is it possible to log all of coming messages from my program that I run via the SSH Secure Shell client. for example: ./test and my program will run with giving debug lines. how can I log the debug lines to a txt file for analysing?

Have you tryed?
./test > log.txt

Related

Run command multiple linux server

One of my tasks at work is to check the health/status of multiple Linux servers everyday. I'm thinking of a way to automate this task (without having to login to each server everyday). I'm a newbie system admin by the way. Initially, my idea was to setup a cron job that would run scripts and email the output. Unfortunately, it's not possible to send mail from the servers as of the moment.
I was thinking of running the command in parallel, but I don't know how. For example, how can I see output of df -h without logging in to servers one by one.
You can run ssh with the -t flag to open a ssh session, run a command and then close the session. But to get this fully automated you should automate the login process to every server so that you don't need to type the password for every server.
So to run df -hon a remote server and then close the session you would run ssh -t root#server.com "df -h". Then you can process that output however you want.
One way of automating this could be to write a bash script that runs this command for every server and process the output to check the health of the server.
For further information about the -t flag or how you can automate the login process for ssh.
https://www.novell.com/coolsolutions/tip/16747.html
https://serverfault.com/questions/241588/how-to-automate-ssh-login-with-password
You can use ssh tunnels or just simply ssh for this purpose. With ssh tunnel you can redirect the outputs to your machine, or as an alternative, you can run the ssh with the remote commands on your machine then get the ouput on your machine too.
Please check the following pages for further reading:
http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html
https://www.google.hu/amp/s/www.cyberciti.biz/faq/unix-linux-execute-command-using-ssh/amp/
If you want to avoid manual login, use ssh keys.
Create a file /etc/sxx/hosts
populate like so:
[grp_ips]
1.1.1.1
2.2.2.2
3.3.3.3
share ssh key on all machines.
Install sxx from package:
https://github.com/ericcurtin/sxx/releases
Then run command like so:
sxx username#grp_ips "whatever bash command"

Running history command remotely in linux

My requirement is to save history of the commands into a file called history_yymmdd.txt by running the following command on a remote server.
history > history_20170523.txt
I tried with the following command, but it was creating a blank file on remote server(10.12.13.14).
ssh 10.12.13.14 "history > history_20170523.txt"
When I log in to the remote server and run the history command, then the file was created successfully. But I need to run the command on 20 servers so creating a script to run it remotely on each server is my objective here.
Thanks in advance.
ssh user#machine_name "cat ~/.bash_history > history_20170523.txt"
The 'history' command dumps the contents of .bash_history, so this may be useful to you.
A more elegant solution might be:
scp user#machine_name:~/.bash_history history_20170523.txt
you are doing it in a wrong way, also there is no user for the remote machine. Correct way to do is
ssh -q -tt user#10.12.13.14 'history > history_20170523.txt'

Using local system as ssh client and server

I am using local system to learn ssh and what I am trying to do is execute a command on the remote server.
I have ssh server running on terminal1 and client on terminal2.
I used the following command on terminal2:
ssh user1#127.0.0.1 echo Display this.
but it echoes on terminal2. How would I know if the command actually worked if it's not displaying in terminal1?
Thank you.
It worked correctly. It ssh'd into the server, executed the command, and returned the stdout of that command back to you.
SSH gains access to the server, but not necessarily any TTY's active on it. You would have to jump through some hoops to send text to a specific TTY, such as your Terminal1.
A better test would be:
ssh user1#127.0.0.1 'touch ~/testfile'
Then you can check on your server (which is localhost) to see if testfile was created in your user1 home folder. If it did, then the connection and the command succeeded.

Is it possible to write a script that will ssh to client and dump log file, and download it to your server

My code below doesn't work, when ssh to client and dump log file to the server. Please look at the code below.
ssh 192.168.0.10
dmesg >>/log.txt
You need to include the command to run on the server as part of your ssh command. You can then do the output redirection on the client side:
ssh 192.168.0.10 'dmesg' >> local_file.log
As Khanna111 mentions, this will require a password to be entered (by default), which you can avoid by setting up SSH keys for passwordless login.
How about doing ssh to the client and run the dmesg command and then rsync the logs back. Assuming you can use rsync.
You could also have a CRON that periodically run on the client that invokes dmesg and dumps the log file which can subsequently be copied over. This way you do not have to do an explict ssh.
Another option that I would prefer is to get rysnc to run the command "dmesg" before the transfer. The parameter to use is --rsync-path. The details are explained here: http://www.schwertly.com/2013/07/forcing-rsync-to-create-a-remote-path-using-rsync-path/
EDIT 1: I am assuming that in case of ssh, you have thought about password less logins and the setup they require.

Redirecting Terminal Output of Running Process

I am connecting to a server using SSH and running a minecraft server there with
java -jar server.jar
Now, i want to be able to close my SSH session without closing the minecraft server and, if i need to type some commands to the server or read the server output, i want to be able to re-connect with SSH and get the output and input back to my terminal window.
Is this possible? I've read about redirecting the output to a file, but that won't solve my problem :/
I will use screen to detach and reattach the window.
https://www.digitalocean.com/community/articles/how-to-set-up-a-minecraft-server-on-linux

Resources