Friday, March 1, 2019

store / remove ssh key (git passphrase)



********************
*
********************
$ eval $(ssh-agent)
## The output without the eval will look like this:
$ ssh-agent
ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-hvcwJQnSOHOi/agent.125894; export SSH_AUTH_SOCK;
SSH_AGENT_PID=125895; export SSH_AGENT_PID;
echo Agent pid 125895;

After the ssh-agent is started (with the eval). You can add SSH keys with ssh-add

$ ssh-add ~/.ssh/google
$ ssh-add ~/.ssh/id_rsa

With current versions of SSH you can also add the option AddKeysToAgent to the ~/.ssh/config file:

## ~/.ssh/config
AddKeysToAgent yes


********************
* Remove known host
********************
ssh-keygen -R 192.168.123.254

********************
*
********************
~/.bashrc
SSH_ENV=$HOME/.ssh/environment
# start the ssh-agent
function start_agent {
    echo "Initializing new SSH agent..."
    # spawn ssh-agent
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
    echo succeeded
    chmod 600 ${SSH_ENV}
    . ${SSH_ENV} > /dev/null
    /usr/bin/ssh-add
}

if [ -f "${SSH_ENV}" ]; then
     . ${SSH_ENV} > /dev/null
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi


********************
* MacBook
********************

As of macOS Sierra 10.12.2 Apple added an ssh_config option called UseKeychain which allows a 'proper' resolution to the problem. Add the following to your ~/.ssh/config file:

Wednesday, February 27, 2019

execute a script on a remote machine over ssh using expect


https://linux.die.net/man/1/expect
https://www.blogger.com/blogger.g?blogID=7297027245100107097#allposts/postNum=0

* clock
https://www.tcl.tk/man/tcl8.5/tutorial/Tcl41.html

on Macbook
brew install expect

on Ubuntu
sudo apt install expect

expect.sh

------------------------------

#!/bin/bash
nodeIp=192.168.1.176

(expect -c '
#exp_internal 1
#set timeout 15
spawn ssh root@'$nodeIp'
#expect {
#        ")? " { send "yes\r" ; exp_continue }
#        "# " { send "\r" }
#        }
expect "# "
send "rm /var/log/messages*\r"
expect "# "
send "reboot\r"
expect "# "
#send "exit\r"
    expect eof ')

------------------------------

#!/bin/bash
#foreach {host user password target} $argv {break}

#set command "ping -c 1 $target"
#send "$command\r"

#log_user 0                   ;# turn off the usual output
#expect -re "(yes/no)"
#send "yes\r"
#sleep 1

nodeIp=192.168.1.176

(
expect -c '
#exp_internal 1
#set timeout 20

set command "i2cget -y 1 0x1c 0x14"

spawn ssh root@'$nodeIp'
#expect {
#        ")? " { send "yes\r" ; exp_continue }
#        "# " { send "\r" }
#        }

expect "~# "
send_user "running $command\r\n"

send "$command\r"
expect "0x04"
send "\r"
# puts "$expect_out(0,string)\n"
if {$expect_out(0,string) == "0x04"} {
puts "output of i2cget -y 1 0x1c 0x14 is 0x04\n"
} else {
puts "False\n"
}
# puts "$expect_out(buffer)"

send "\r"
expect "~# "

send "exit\r"
expect eof '
)

Monday, February 4, 2019

taskset example


-p [process id]
./taskset -p 1760 
pid 1760's current affinity mask: f

/taskset -cp 1760
pid 1760's current affinity list: 0-3


taskset -p 0x4 1760

assign it to core0 and core3
taskset -cp 0,3 9726

Wednesday, November 7, 2018

mesh ttl

 - mesh_ttl - for data frames
 - mesh_element_ttl - for management frames

Monday, November 5, 2018

Saturday, October 20, 2018

OpenWrt setting TimeZone

root@EbMajor:~# cat /etc/TZ
PST8PDT,M3.2.0,M11.1.0

root@EbMajor:~# uci show system
system.@system[0]=system
system.@system[0].hostname='EbMajor'
system.@system[0].log_size='64'
system.@system[0].zonename='America/Los Angeles'
system.@system[0].timezone='PST8PDT,M3.2.0,M11.1.0'
system.@system[0].conloglevel='8'
system.@system[0].cronloglevel='8'
system.ntp=timeserver
system.ntp.server='0.openwrt.pool.ntp.org' '1.openwrt.pool.ntp.org' '2.openwrt.pool.ntp.org' '3.openwrt.pool.ntp.org'
system.ntp.enabled='1'
system.ntp.enable_server='1'

Tuesday, October 16, 2018